Flurex Microbiome Beta Diversity

1 BETA DIVERSITY

This Rmarkdown contains the commands necessary to perform beta diversity analysis of the output from the DF_GMH_PIPELINE. It is expected that the data has been imported, cleaned, and saved following the script 1_Import_QC.Rmd prior to using this script. I recommend visiting the “Analysis of community ecology data in R” to read about the theory behind the alpha and beta diversity and examples of the necessary R-code to execute them. Other excellent source of help is the R cheat-sheets and for problems related to Rmarkdown I suggest this online Book.

Beta diversity, also called “between sample diversity” is a measurement of the distance, or difference, between samples. First step will be to calculate the beta diversity, second to identify batch effects, and lastly to determine project effects

2 INFO

This document has been fitted to perform beta diversity calculations of phyloseq element from the Import & QC script. It has been fitted for data from Flurex (internal project name: R20-22). The project data contains 16S V3 amplicon sequencing from feces samples from 4 different days and cecum and ileum samples from one day from 48 rats. There are feces samples from all rats from day 0, 2, 4 and 8. Cecum and ileum samples were all collected at dissection on day 8. Please read the method section for this paper for details on experimental setup.

Metadata contains sample information regarding: - rat number/name, cage number (rats were co-caged 2-2), day of sampling, material (feces, cecum, ileum), sequencing information (gram of material used for extracted DNA, DNA concentrations, primers, barcodes for demultiplexing, batch number (“run” = c2, c3, c4)), treatment groups. Several columns have been created for easy sample grouping during analysis, including for distinguishing between vancomycin and PFOS treatment alone.

Metadata contains results from: - Bodyweight per sampling day, while cecum and liver weight for day 8 (addition column with organ weights normalised to bodyweight).

  • PFOS quantification of:
    • Blood serum from day 4 and 8 measured in µg/mL
    • Liver tissue from day 8 measured in mg PFOS in full liver weight
  • Short-chain fatty acids quantification of 10 compounds in colonic water given in mM from day 8: acetic acid, formic acid, propanoic acid, 2methyl-propanoic acid, butanoic acid, 3methyl-butanoic acid, pentanoic acid, 4methyl-pentanoic acid, hexanoic acid and heptanoic acid
knitr::opts_chunk$set(echo = TRUE)

# Load libraries
library(tidyverse)
library(phyloseq)
library(ggpubr)
library(rstatix)
library(vegan)
library(ape)
library(kableExtra)
library(reshape2)
library(dplyr)
library(ggplot2)
library(cowplot)
library(ggExtra)

# Create used folders if missing
if (!file.exists("R_objects")) dir.create(file.path(getwd(), "R_objects"))
if (!file.exists("plots")) dir.create(file.path(getwd(), "plots"))
if (!file.exists("plots/bdiv")) dir.create(file.path(getwd(), "plots/bdiv"))
if (!file.exists("tables")) dir.create(file.path(getwd(), "tables"))
if (!file.exists("scripts")) dir.create(file.path(getwd(), "scripts"))

# Save params
saveRDS(params, file = "R_Objects/bdiv_params.RDS")

2.1 SCRIPTS

This section contains the scripts for the custom functions used in this pipeline

2.1.1 MULTIPLE RAREFY

Here is a function that rarefies each sample of a phyloseq object, calculates the distance between them, and chooses the most central as a representative sample for any following analyses.

multiple_rarefy <- function(physeq, ntables=100, depth = min(rowSums(rawtab))*0.9, distmethod="bray", summarymeasure=mean, seedstart=500, verbose=TRUE) {
  require("vegan")
  # Orientate the OTU correctly
  if (taxa_are_rows(physeq)){rawtab<-unclass(t(otu_table(physeq)))} else rawtab <- unclass(otu_table(physeq))
  
  # Ignore samples below rarefaction depth
  ind <- (rowSums(rawtab) < depth)
  sam.discard <- rownames(rawtab)[ind]
  otu.tab <- rawtab[!ind, ]
  
  # Rarefaction function
  rarefy <- function(x, depth) {
    y <- sample(rep(1:length(x), x), depth)
    y.tab <- table(y)
    j <- numeric(length(x))
    j[as.numeric(names(y.tab))] <- y.tab
    j
  }
  
  # Table to output rarefied data
  final_tab = c()
  
  # Run each sample separately
  for (z in 1:nrow(otu.tab)) {
    if (verbose==TRUE) {
      print(paste("Rarefaction sample number", z, sep=" "))
    }
    numbers <- otu.tab[z,]
    
    # Rarefy the sample ntables times
    set.seed(seedstart + z)
    rare_tab <- lapply(1:ntables,function(k) rarefy(numbers,depth))
    
    rare_tab <- do.call(rbind, rare_tab)
    # # Remove columns with no reads
    # rare_tab_no_zero <- rare_tab[,colSums(rare_tab) != 0]
    # # distance across reps for subject z
    distmat = as.matrix(vegdist(rare_tab, method=distmethod)) 
    # calculate mean distance for each rep 
    distsummary = apply(distmat, 2, summarymeasure)
    # the best rep is the one with the mean distance to all other reps. (in case of ties, just select the first)
    whichbestrep = which(distsummary == min(distsummary))[1]  
    # select that rep only for subject z
    bestrep = rare_tab[whichbestrep,]
    # build that rep for subject y into final table
    final_tab = rbind(final_tab, bestrep) 
  }
  
  # Remove samples with too few reads
  physeq <- prune_samples(!sample_names(physeq) %in% sam.discard, physeq) 
  # Reformat final tab and return to the physeq object
  rownames(final_tab) = rownames(otu.tab)
  colnames(final_tab) = colnames(otu.tab)
  otu_table(physeq) <- otu_table(t(final_tab), taxa_are_rows = T)
  
  # Return physeq to the environment
  return(physeq)
}

# save functions
save(multiple_rarefy, file = "scripts/mrarefy.Rdata")

# clear the environment and release memory
rm(list = ls(all.names = TRUE)) #will clear all objects includes hidden objects.
invisible(gc()) #free up memory and report the memory usage.

2.2 CALCULATE BETA DIVERSITY

I will calculate for both weighted UniFrac distances and Bray-Curtis dissimilarity index. Both indeces normalises pairwise distances/dissimilarities to be between 0 and 1, which means that while the distance between two samples will always be the same, the numerical value will depend on all the samples analysed together. Other metrics/indeces can be used, and might be relevant, but just keep in mind how the specific indeces are relevant for the interpretation of the following results.

2.2.1 CREATE RAREFIED PHYLOSEQ OBJECT

Most beta diversity metrics that are based on presence/absence of bacteria are sensitive to differences in sequencing depth. The way to minimize such bias is to perform rarefaction of the data, but as rarefaction is random this introduces yet another bias. Here we will rarefy each sample multiple times and choose the most central as a representative rarefication.

params <- readRDS("R_objects/bdiv_params.RDS")
load("scripts/mrarefy.Rdata")

# Load phyloseq
load(params$input)

# Perform multiple rarefactions
phy.rare <- multiple_rarefy(phy)
## [1] "Rarefaction sample number 1"
## [1] "Rarefaction sample number 2"
## [1] "Rarefaction sample number 3"
## [1] "Rarefaction sample number 4"
## [1] "Rarefaction sample number 5"
## [1] "Rarefaction sample number 6"
## [1] "Rarefaction sample number 7"
## [1] "Rarefaction sample number 8"
## [1] "Rarefaction sample number 9"
## [1] "Rarefaction sample number 10"
## [1] "Rarefaction sample number 11"
## [1] "Rarefaction sample number 12"
## [1] "Rarefaction sample number 13"
## [1] "Rarefaction sample number 14"
## [1] "Rarefaction sample number 15"
## [1] "Rarefaction sample number 16"
## [1] "Rarefaction sample number 17"
## [1] "Rarefaction sample number 18"
## [1] "Rarefaction sample number 19"
## [1] "Rarefaction sample number 20"
## [1] "Rarefaction sample number 21"
## [1] "Rarefaction sample number 22"
## [1] "Rarefaction sample number 23"
## [1] "Rarefaction sample number 24"
## [1] "Rarefaction sample number 25"
## [1] "Rarefaction sample number 26"
## [1] "Rarefaction sample number 27"
## [1] "Rarefaction sample number 28"
## [1] "Rarefaction sample number 29"
## [1] "Rarefaction sample number 30"
## [1] "Rarefaction sample number 31"
## [1] "Rarefaction sample number 32"
## [1] "Rarefaction sample number 33"
## [1] "Rarefaction sample number 34"
## [1] "Rarefaction sample number 35"
## [1] "Rarefaction sample number 36"
## [1] "Rarefaction sample number 37"
## [1] "Rarefaction sample number 38"
## [1] "Rarefaction sample number 39"
## [1] "Rarefaction sample number 40"
## [1] "Rarefaction sample number 41"
## [1] "Rarefaction sample number 42"
## [1] "Rarefaction sample number 43"
## [1] "Rarefaction sample number 44"
## [1] "Rarefaction sample number 45"
## [1] "Rarefaction sample number 46"
## [1] "Rarefaction sample number 47"
## [1] "Rarefaction sample number 48"
## [1] "Rarefaction sample number 49"
## [1] "Rarefaction sample number 50"
## [1] "Rarefaction sample number 51"
## [1] "Rarefaction sample number 52"
## [1] "Rarefaction sample number 53"
## [1] "Rarefaction sample number 54"
## [1] "Rarefaction sample number 55"
## [1] "Rarefaction sample number 56"
## [1] "Rarefaction sample number 57"
## [1] "Rarefaction sample number 58"
## [1] "Rarefaction sample number 59"
## [1] "Rarefaction sample number 60"
## [1] "Rarefaction sample number 61"
## [1] "Rarefaction sample number 62"
## [1] "Rarefaction sample number 63"
## [1] "Rarefaction sample number 64"
## [1] "Rarefaction sample number 65"
## [1] "Rarefaction sample number 66"
## [1] "Rarefaction sample number 67"
## [1] "Rarefaction sample number 68"
## [1] "Rarefaction sample number 69"
## [1] "Rarefaction sample number 70"
## [1] "Rarefaction sample number 71"
## [1] "Rarefaction sample number 72"
## [1] "Rarefaction sample number 73"
## [1] "Rarefaction sample number 74"
## [1] "Rarefaction sample number 75"
## [1] "Rarefaction sample number 76"
## [1] "Rarefaction sample number 77"
## [1] "Rarefaction sample number 78"
## [1] "Rarefaction sample number 79"
## [1] "Rarefaction sample number 80"
## [1] "Rarefaction sample number 81"
## [1] "Rarefaction sample number 82"
## [1] "Rarefaction sample number 83"
## [1] "Rarefaction sample number 84"
## [1] "Rarefaction sample number 85"
## [1] "Rarefaction sample number 86"
## [1] "Rarefaction sample number 87"
## [1] "Rarefaction sample number 88"
## [1] "Rarefaction sample number 89"
## [1] "Rarefaction sample number 90"
## [1] "Rarefaction sample number 91"
## [1] "Rarefaction sample number 92"
## [1] "Rarefaction sample number 93"
## [1] "Rarefaction sample number 94"
## [1] "Rarefaction sample number 95"
## [1] "Rarefaction sample number 96"
## [1] "Rarefaction sample number 97"
## [1] "Rarefaction sample number 98"
## [1] "Rarefaction sample number 99"
## [1] "Rarefaction sample number 100"
## [1] "Rarefaction sample number 101"
## [1] "Rarefaction sample number 102"
## [1] "Rarefaction sample number 103"
## [1] "Rarefaction sample number 104"
## [1] "Rarefaction sample number 105"
## [1] "Rarefaction sample number 106"
## [1] "Rarefaction sample number 107"
## [1] "Rarefaction sample number 108"
## [1] "Rarefaction sample number 109"
## [1] "Rarefaction sample number 110"
## [1] "Rarefaction sample number 111"
## [1] "Rarefaction sample number 112"
## [1] "Rarefaction sample number 113"
## [1] "Rarefaction sample number 114"
## [1] "Rarefaction sample number 115"
## [1] "Rarefaction sample number 116"
## [1] "Rarefaction sample number 117"
## [1] "Rarefaction sample number 118"
## [1] "Rarefaction sample number 119"
## [1] "Rarefaction sample number 120"
## [1] "Rarefaction sample number 121"
## [1] "Rarefaction sample number 122"
## [1] "Rarefaction sample number 123"
## [1] "Rarefaction sample number 124"
## [1] "Rarefaction sample number 125"
## [1] "Rarefaction sample number 126"
## [1] "Rarefaction sample number 127"
## [1] "Rarefaction sample number 128"
## [1] "Rarefaction sample number 129"
## [1] "Rarefaction sample number 130"
## [1] "Rarefaction sample number 131"
## [1] "Rarefaction sample number 132"
## [1] "Rarefaction sample number 133"
## [1] "Rarefaction sample number 134"
## [1] "Rarefaction sample number 135"
## [1] "Rarefaction sample number 136"
## [1] "Rarefaction sample number 137"
## [1] "Rarefaction sample number 138"
## [1] "Rarefaction sample number 139"
## [1] "Rarefaction sample number 140"
## [1] "Rarefaction sample number 141"
## [1] "Rarefaction sample number 142"
## [1] "Rarefaction sample number 143"
## [1] "Rarefaction sample number 144"
## [1] "Rarefaction sample number 145"
## [1] "Rarefaction sample number 146"
## [1] "Rarefaction sample number 147"
## [1] "Rarefaction sample number 148"
## [1] "Rarefaction sample number 149"
## [1] "Rarefaction sample number 150"
## [1] "Rarefaction sample number 151"
## [1] "Rarefaction sample number 152"
## [1] "Rarefaction sample number 153"
## [1] "Rarefaction sample number 154"
## [1] "Rarefaction sample number 155"
## [1] "Rarefaction sample number 156"
## [1] "Rarefaction sample number 157"
## [1] "Rarefaction sample number 158"
## [1] "Rarefaction sample number 159"
## [1] "Rarefaction sample number 160"
## [1] "Rarefaction sample number 161"
## [1] "Rarefaction sample number 162"
## [1] "Rarefaction sample number 163"
## [1] "Rarefaction sample number 164"
## [1] "Rarefaction sample number 165"
## [1] "Rarefaction sample number 166"
## [1] "Rarefaction sample number 167"
## [1] "Rarefaction sample number 168"
## [1] "Rarefaction sample number 169"
## [1] "Rarefaction sample number 170"
## [1] "Rarefaction sample number 171"
## [1] "Rarefaction sample number 172"
## [1] "Rarefaction sample number 173"
## [1] "Rarefaction sample number 174"
## [1] "Rarefaction sample number 175"
## [1] "Rarefaction sample number 176"
## [1] "Rarefaction sample number 177"
## [1] "Rarefaction sample number 178"
## [1] "Rarefaction sample number 179"
## [1] "Rarefaction sample number 180"
## [1] "Rarefaction sample number 181"
## [1] "Rarefaction sample number 182"
## [1] "Rarefaction sample number 183"
## [1] "Rarefaction sample number 184"
## [1] "Rarefaction sample number 185"
## [1] "Rarefaction sample number 186"
## [1] "Rarefaction sample number 187"
## [1] "Rarefaction sample number 188"
## [1] "Rarefaction sample number 189"
## [1] "Rarefaction sample number 190"
## [1] "Rarefaction sample number 191"
## [1] "Rarefaction sample number 192"
## [1] "Rarefaction sample number 193"
## [1] "Rarefaction sample number 194"
## [1] "Rarefaction sample number 195"
## [1] "Rarefaction sample number 196"
## [1] "Rarefaction sample number 197"
## [1] "Rarefaction sample number 198"
## [1] "Rarefaction sample number 199"
## [1] "Rarefaction sample number 200"
## [1] "Rarefaction sample number 201"
## [1] "Rarefaction sample number 202"
## [1] "Rarefaction sample number 203"
## [1] "Rarefaction sample number 204"
## [1] "Rarefaction sample number 205"
## [1] "Rarefaction sample number 206"
## [1] "Rarefaction sample number 207"
## [1] "Rarefaction sample number 208"
## [1] "Rarefaction sample number 209"
## [1] "Rarefaction sample number 210"
## [1] "Rarefaction sample number 211"
## [1] "Rarefaction sample number 212"
## [1] "Rarefaction sample number 213"
## [1] "Rarefaction sample number 214"
## [1] "Rarefaction sample number 215"
## [1] "Rarefaction sample number 216"
## [1] "Rarefaction sample number 217"
## [1] "Rarefaction sample number 218"
## [1] "Rarefaction sample number 219"
## [1] "Rarefaction sample number 220"
## [1] "Rarefaction sample number 221"
## [1] "Rarefaction sample number 222"
## [1] "Rarefaction sample number 223"
## [1] "Rarefaction sample number 224"
## [1] "Rarefaction sample number 225"
## [1] "Rarefaction sample number 226"
## [1] "Rarefaction sample number 227"
## [1] "Rarefaction sample number 228"
## [1] "Rarefaction sample number 229"
## [1] "Rarefaction sample number 230"
## [1] "Rarefaction sample number 231"
## [1] "Rarefaction sample number 232"
## [1] "Rarefaction sample number 233"
## [1] "Rarefaction sample number 234"
## [1] "Rarefaction sample number 235"
## [1] "Rarefaction sample number 236"
## [1] "Rarefaction sample number 237"
## [1] "Rarefaction sample number 238"
## [1] "Rarefaction sample number 239"
## [1] "Rarefaction sample number 240"
## [1] "Rarefaction sample number 241"
## [1] "Rarefaction sample number 242"
## [1] "Rarefaction sample number 243"
## [1] "Rarefaction sample number 244"
## [1] "Rarefaction sample number 245"
## [1] "Rarefaction sample number 246"
## [1] "Rarefaction sample number 247"
## [1] "Rarefaction sample number 248"
## [1] "Rarefaction sample number 249"
## [1] "Rarefaction sample number 250"
## [1] "Rarefaction sample number 251"
## [1] "Rarefaction sample number 252"
## [1] "Rarefaction sample number 253"
## [1] "Rarefaction sample number 254"
## [1] "Rarefaction sample number 255"
## [1] "Rarefaction sample number 256"
## [1] "Rarefaction sample number 257"
## [1] "Rarefaction sample number 258"
## [1] "Rarefaction sample number 259"
## [1] "Rarefaction sample number 260"
## [1] "Rarefaction sample number 261"
## [1] "Rarefaction sample number 262"
## [1] "Rarefaction sample number 263"
## [1] "Rarefaction sample number 264"
## [1] "Rarefaction sample number 265"
## [1] "Rarefaction sample number 266"
## [1] "Rarefaction sample number 267"
# Remove empty taxa
phy.rare <- prune_taxa(taxa_sums(phy.rare) > 0, phy.rare)

# Root tree
phy_tree(phy) <- ape::root(phy_tree(phy), sample(taxa_names(phy), 1), resolve.root = TRUE)

# Save object
save(phy.rare, file = "R_objects/Phyloseq_rarefied.Rdata")

# clear the environment and release memory
rm(list = ls(all.names = TRUE)) #will clear all objects includes hidden objects.
invisible(gc()) #free up memory and report the memory usage.

2.2.2 UNWEIGHTED UNIFRAC

The unique fraction metric, or UniFrac, measures the phylogenetic distance between sets of taxa in a phylogenetic tree as the fraction of the branch length of the tree that leads to descendants from either one environment or the other, but not both (Lozupone & Knight, 2005). This metric is sensitive to sequencing depth, so it is required to use a rarefied phyloseq object The UniFrac algorithm requires a rooted tree, so if ASVs has been removed from the raw da the tree should be rerooted manually, else a random ASV will be chosen as root.

params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("scripts/mrarefy.Rdata")

# Root tree if necessary
if (!is.rooted(phy_tree(phy.rare))) phy_tree(phy.rare) <- ape::root(phy_tree(phy.rare), sample(taxa_names(phy.rare), 1), resolve.root = TRUE)

# Calculate UniFrac distances
unif.dist <- UniFrac(phy.rare, weighted = FALSE, parallel = FALSE)

# Calculate PCoA data
unif.pcoa <- ordinate(phy.rare, method = "PCoA",distance = unif.dist)
unif.nmds <- metaMDS(unif.dist, k = 5, trymax = 1000)

# Save distance objects
save(unif.dist, unif.nmds, unif.pcoa, file = "R_objects/UniF.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())

2.2.2.1 SUBSETS

2.2.2.1.1 Feces
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day %in% c("d0","d2","d4","d8"))

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f0248.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f0.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f2.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f4.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day %in% c("d0","d8"))

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f08.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.2.1.2 Feces, Cecum, Ileum
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.fceil8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8" & material == "Cecum")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.ce8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8" & material == "Ileum")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.il8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.2.1.3 Feces non-Vancomycin and Vancomycin
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f0_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f0_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f2_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f2_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f4_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f4_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.f8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.2.1.4 Cecum & Ileum non-Vancomycin and Vancomycin
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Cecum" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.ce8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Cecum" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.ce8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Ileum" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.il8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Ileum" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.il8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.2.1.5 Feces diversity over time
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "CTRL") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.feces_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "PFOS") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.feces_pfos.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "VAN") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.feces_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

tmp.dist <- as.matrix(unif.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "VAN+PFOS") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
unif.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
unif.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = unif.sub.dist)
unif.sub.nmds <- metaMDS(unif.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, unif.sub.dist, unif.sub.nmds, unif.sub.pcoa, file = "R_objects/unif.sub.feces_vanpfos.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())

2.2.3 WEIGHTED UNIFRAC

The unique fraction metric, or UniFrac, measures the phylogenetic distance between sets of taxa in a phylogenetic tree as the fraction of the branch length of the tree that leads to descendants from either one environment or the other, but not both (Lozupone & Knight, 2005). Weighted UniFrac takes the abundance of each ASV into account instead of just presence/absence, which means that it will not be sensitive to sequencing depth. The UniFrac algorithm requires a rooted tree, so if ASVs has been removed from the raw da the tree should be rerooted manually, else a random ASV will be chosen as root.

params <- readRDS("R_objects/bdiv_params.RDS")
# load
load(params$input)

# Root tree if necessary
if (!is.rooted(phy_tree(phy))) phy_tree(phy) <- ape::root(phy_tree(phy), sample(taxa_names(phy), 1), resolve.root = TRUE)

# Calculate UniFrac distances
wuf.dist <- UniFrac(phy, weighted = TRUE, parallel = FALSE)

# Calculate PCoA data
wuf.pcoa <- ordinate(phy, method = "PCoA",distance = wuf.dist)
wuf.nmds <- metaMDS(wuf.dist, k = 5, trymax = 1000)

# Save distance objects
save(wuf.dist, wuf.nmds, wuf.pcoa, file = "R_objects/wuf.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())

2.2.3.1 SUBSETS

2.2.3.1.1 Feces
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day %in% c("d0","d2","d4","d8"))

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f0248.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f0.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f2.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f4.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day %in% c("d0","d8"))

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f08.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.3.1.2 Feces, Cecum, Ileum
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.fceil8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8" & material == "Cecum")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.ce8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8" & material == "Ileum")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.il8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.3.1.3 Feces non-Vancomycin and Vancomycin
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f0_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f0_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f2_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f2_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f4_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f4_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.f8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.3.1.4 Cecum & Ileum non-Vancomycin and Vancomycin
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Cecum" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.ce8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Cecum" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.ce8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Ileum" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.il8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Ileum" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.il8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.3.1.5 Feces diversity over time
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "CTRL") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.feces_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "PFOS") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.feces_pfos.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "VAN") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.feces_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/wuf.RData")

tmp.dist <- as.matrix(wuf.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "VAN+PFOS") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
wuf.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUniFrac distances

# Calculate PCoA data
wuf.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = wuf.sub.dist)
wuf.sub.nmds <- metaMDS(wuf.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa, file = "R_objects/wuf.sub.feces_vanpfos.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())

2.2.4 BRAY-CURTIS

Bray-Curtis dissimilarity index (as implemented by the vegan package) is the sum of abundance difference for each species/ASV, divided by theoretical maximum difference between the samples if no ASV overlapped. The formula used is: \[d_{jk} = \frac{\sum|n_{ij}-n_{ik}|}{\sum(n_{ij}+n_{ik})}\] Bray-Curtis dissimilarity is not a true distance metric as it does not adhere to the triangle inequality, but is often used to compare microbiomes. Bray-Curtis dissimilarities are based on the assumption that measurements are taken from equal areas, so differences in total counts between samples will bias the metric. As differences in sequences depth is due to differences in the lab procedures and not biological differences, we should transform our counts to relative abundances before calculating Bray-Curtis dissimilarities. By transforming the data to abundances no data is lost, but rarefied data can also be used.

params <- readRDS("R_objects/bdiv_params.RDS")
# load
load(params$input)

# transform counts to relative abundance
phy.ra <- transform_sample_counts(phy, function(x) x/sum(x))

# Calculate Bray-Curtis dissimilarities
bray.dist <- distance(phy.ra, method = "bray",)

# Calculate PCoA data
bray.pcoa <- ordinate(phy, method = "PCoA",distance = bray.dist)
bray.nmds <- metaMDS(bray.dist, k = 5, trymax = 1000)

# Save distance objects
save(bray.dist, bray.nmds, bray.pcoa, file = "R_objects/Bray.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())

2.2.4.1 SUBSETS

2.2.4.1.1 Feces
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day %in% c("d0","d2","d4","d8"))

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f0248.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f0.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f2.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f4.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day %in% c("d0","d8"))

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f08.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.4.1.2 Feces, Cecum, Ileum
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.fceil8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8" & material == "Cecum")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.ce8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8" & material == "Ileum")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.il8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.4.1.3 Feces non-Vancomycin and Vancomycin
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f0_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f0_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f2_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f2_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f4_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f4_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.f8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.4.1.4 Cecum & Ileum non-Vancomycin and Vancomycin
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Cecum" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.ce8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Cecum" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.ce8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Ileum" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.il8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Ileum" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.il8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.4.1.5 Feces diversity over time
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "CTRL") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.feces_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "PFOS") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.feces_pfos.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "VAN") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.feces_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/Bray.RData")

tmp.dist <- as.matrix(bray.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "VAN+PFOS") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
bray.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Brayrac distances

# Calculate PCoA data
bray.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = bray.sub.dist)
bray.sub.nmds <- metaMDS(bray.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, bray.sub.dist, bray.sub.nmds, bray.sub.pcoa, file = "R_objects/bray.sub.feces_vanpfos.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())

2.2.5 JACCARD

params <- readRDS("R_objects/bdiv_params.RDS")
# load
load(params$input)

# transform counts
phy.ra <- transform_sample_counts(phy, function(x) x/sum(x))

# Calculate Jaccard distances
jac.dist <- distance(phy.ra, method = "jaccard", binary = TRUE)

# Calculate PCoA data
jac.pcoa <- ordinate(phy, method = "PCoA",distance = jac.dist)
jac.nmds <- metaMDS(jac.dist, k = 5, trymax = 1000)
## Run 0 stress 0.05236117 
## Run 1 stress 0.05198686 
## ... New best solution
## ... Procrustes: rmse 0.01489516  max resid 0.1057997 
## Run 2 stress 0.05172856 
## ... New best solution
## ... Procrustes: rmse 0.01494549  max resid 0.1012656 
## Run 3 stress 0.0530997 
## Run 4 stress 0.05164876 
## ... New best solution
## ... Procrustes: rmse 0.01224554  max resid 0.1026199 
## Run 5 stress 0.05243544 
## Run 6 stress 0.05203302 
## ... Procrustes: rmse 0.01580935  max resid 0.06489065 
## Run 7 stress 0.05227685 
## Run 8 stress 0.0520533 
## ... Procrustes: rmse 0.01157199  max resid 0.05827736 
## Run 9 stress 0.0522513 
## Run 10 stress 0.05229409 
## Run 11 stress 0.05221449 
## Run 12 stress 0.05210081 
## ... Procrustes: rmse 0.01546179  max resid 0.06280289 
## Run 13 stress 0.05192376 
## ... Procrustes: rmse 0.01633182  max resid 0.1075986 
## Run 14 stress 0.05234046 
## Run 15 stress 0.05174342 
## ... Procrustes: rmse 0.008691435  max resid 0.06100312 
## Run 16 stress 0.05211676 
## ... Procrustes: rmse 0.01533702  max resid 0.08624318 
## Run 17 stress 0.05207934 
## ... Procrustes: rmse 0.01508554  max resid 0.1071542 
## Run 18 stress 0.05229757 
## Run 19 stress 0.05768495 
## Run 20 stress 0.05310085 
## Run 21 stress 0.05220085 
## Run 22 stress 0.05170812 
## ... Procrustes: rmse 0.01108809  max resid 0.1030309 
## Run 23 stress 0.05252854 
## Run 24 stress 0.0517865 
## ... Procrustes: rmse 0.01154381  max resid 0.06380819 
## Run 25 stress 0.05250524 
## Run 26 stress 0.0521471 
## ... Procrustes: rmse 0.01699978  max resid 0.08447267 
## Run 27 stress 0.05171398 
## ... Procrustes: rmse 0.0074967  max resid 0.05515589 
## Run 28 stress 0.05176563 
## ... Procrustes: rmse 0.01119219  max resid 0.07203493 
## Run 29 stress 0.05284378 
## Run 30 stress 0.05175807 
## ... Procrustes: rmse 0.008699831  max resid 0.05843006 
## Run 31 stress 0.05175858 
## ... Procrustes: rmse 0.008836879  max resid 0.06761054 
## Run 32 stress 0.05192497 
## ... Procrustes: rmse 0.01210715  max resid 0.1004806 
## Run 33 stress 0.05275693 
## Run 34 stress 0.05208099 
## ... Procrustes: rmse 0.01203525  max resid 0.0747138 
## Run 35 stress 0.05157783 
## ... New best solution
## ... Procrustes: rmse 0.009695998  max resid 0.075864 
## Run 36 stress 0.0518004 
## ... Procrustes: rmse 0.01162119  max resid 0.07338137 
## Run 37 stress 0.05221113 
## Run 38 stress 0.05205883 
## ... Procrustes: rmse 0.01170105  max resid 0.08132292 
## Run 39 stress 0.0525487 
## Run 40 stress 0.05201426 
## ... Procrustes: rmse 0.01361681  max resid 0.1082875 
## Run 41 stress 0.05228951 
## Run 42 stress 0.05212707 
## Run 43 stress 0.051739 
## ... Procrustes: rmse 0.01038838  max resid 0.06674053 
## Run 44 stress 0.05254941 
## Run 45 stress 0.05186002 
## ... Procrustes: rmse 0.01709879  max resid 0.1116073 
## Run 46 stress 0.05232802 
## Run 47 stress 0.05160644 
## ... Procrustes: rmse 0.01199031  max resid 0.0810598 
## Run 48 stress 0.05201473 
## ... Procrustes: rmse 0.01176909  max resid 0.08014085 
## Run 49 stress 0.05288511 
## Run 50 stress 0.05267616 
## Run 51 stress 0.05263135 
## Run 52 stress 0.05187442 
## ... Procrustes: rmse 0.009220837  max resid 0.08122225 
## Run 53 stress 0.05241508 
## Run 54 stress 0.05167399 
## ... Procrustes: rmse 0.01145996  max resid 0.05565025 
## Run 55 stress 0.05182909 
## ... Procrustes: rmse 0.009890512  max resid 0.08112264 
## Run 56 stress 0.05244893 
## Run 57 stress 0.05211323 
## Run 58 stress 0.05202888 
## ... Procrustes: rmse 0.01194004  max resid 0.08120338 
## Run 59 stress 0.05172503 
## ... Procrustes: rmse 0.01456099  max resid 0.1094632 
## Run 60 stress 0.05272074 
## Run 61 stress 0.05208922 
## Run 62 stress 0.05176657 
## ... Procrustes: rmse 0.01277492  max resid 0.1061125 
## Run 63 stress 0.05253705 
## Run 64 stress 0.05159806 
## ... Procrustes: rmse 0.005592757  max resid 0.06458564 
## Run 65 stress 0.0520306 
## ... Procrustes: rmse 0.01323999  max resid 0.08270909 
## Run 66 stress 0.05215637 
## Run 67 stress 0.05246243 
## Run 68 stress 0.05160856 
## ... Procrustes: rmse 0.01018672  max resid 0.05698464 
## Run 69 stress 0.05190103 
## ... Procrustes: rmse 0.01412034  max resid 0.08266975 
## Run 70 stress 0.05257483 
## Run 71 stress 0.05187285 
## ... Procrustes: rmse 0.007292053  max resid 0.08079666 
## Run 72 stress 0.05172588 
## ... Procrustes: rmse 0.01678508  max resid 0.09066998 
## Run 73 stress 0.0546958 
## Run 74 stress 0.05210231 
## Run 75 stress 0.05189682 
## ... Procrustes: rmse 0.01043531  max resid 0.0550441 
## Run 76 stress 0.05157614 
## ... New best solution
## ... Procrustes: rmse 0.007260744  max resid 0.05035941 
## Run 77 stress 0.05195968 
## ... Procrustes: rmse 0.0109458  max resid 0.0810418 
## Run 78 stress 0.0521677 
## Run 79 stress 0.05202632 
## ... Procrustes: rmse 0.009032049  max resid 0.05632924 
## Run 80 stress 0.0517075 
## ... Procrustes: rmse 0.008681328  max resid 0.08855523 
## Run 81 stress 0.05207983 
## Run 82 stress 0.05190212 
## ... Procrustes: rmse 0.01247851  max resid 0.06439091 
## Run 83 stress 0.05263118 
## Run 84 stress 0.05215874 
## Run 85 stress 0.05190509 
## ... Procrustes: rmse 0.01063431  max resid 0.08161859 
## Run 86 stress 0.05184156 
## ... Procrustes: rmse 0.01159653  max resid 0.05723701 
## Run 87 stress 0.05183555 
## ... Procrustes: rmse 0.01079604  max resid 0.05600219 
## Run 88 stress 0.05242454 
## Run 89 stress 0.05176189 
## ... Procrustes: rmse 0.009441139  max resid 0.07988927 
## Run 90 stress 0.05142582 
## ... New best solution
## ... Procrustes: rmse 0.007314945  max resid 0.05652177 
## Run 91 stress 0.05221205 
## Run 92 stress 0.0520277 
## Run 93 stress 0.05213458 
## Run 94 stress 0.05184233 
## ... Procrustes: rmse 0.01140588  max resid 0.0801631 
## Run 95 stress 0.05214961 
## Run 96 stress 0.05172912 
## ... Procrustes: rmse 0.009290972  max resid 0.0659314 
## Run 97 stress 0.05205235 
## Run 98 stress 0.05174236 
## ... Procrustes: rmse 0.007012042  max resid 0.03955373 
## Run 99 stress 0.0521037 
## Run 100 stress 0.05281363 
## Run 101 stress 0.05195017 
## Run 102 stress 0.05170722 
## ... Procrustes: rmse 0.01124655  max resid 0.08058484 
## Run 103 stress 0.05242631 
## Run 104 stress 0.05164924 
## ... Procrustes: rmse 0.01076578  max resid 0.08093671 
## Run 105 stress 0.05156131 
## ... Procrustes: rmse 0.01020842  max resid 0.07014485 
## Run 106 stress 0.05183571 
## ... Procrustes: rmse 0.008673084  max resid 0.08062792 
## Run 107 stress 0.0525408 
## Run 108 stress 0.05283953 
## Run 109 stress 0.05221341 
## Run 110 stress 0.05181753 
## ... Procrustes: rmse 0.01355522  max resid 0.08052416 
## Run 111 stress 0.05186941 
## ... Procrustes: rmse 0.01086743  max resid 0.08111683 
## Run 112 stress 0.05185826 
## ... Procrustes: rmse 0.01482204  max resid 0.1102905 
## Run 113 stress 0.05187604 
## ... Procrustes: rmse 0.01364625  max resid 0.1072727 
## Run 114 stress 0.05216517 
## Run 115 stress 0.05305547 
## Run 116 stress 0.05147982 
## ... Procrustes: rmse 0.006248961  max resid 0.03518915 
## Run 117 stress 0.05252781 
## Run 118 stress 0.05258842 
## Run 119 stress 0.05152631 
## ... Procrustes: rmse 0.01086738  max resid 0.06568775 
## Run 120 stress 0.05205766 
## Run 121 stress 0.05297234 
## Run 122 stress 0.05183373 
## ... Procrustes: rmse 0.01105283  max resid 0.1043297 
## Run 123 stress 0.05163987 
## ... Procrustes: rmse 0.008338933  max resid 0.06581989 
## Run 124 stress 0.0516203 
## ... Procrustes: rmse 0.007781344  max resid 0.05673999 
## Run 125 stress 0.052256 
## Run 126 stress 0.05280732 
## Run 127 stress 0.05235247 
## Run 128 stress 0.05218823 
## Run 129 stress 0.05296697 
## Run 130 stress 0.05169503 
## ... Procrustes: rmse 0.01113132  max resid 0.06813567 
## Run 131 stress 0.05203664 
## Run 132 stress 0.05201954 
## Run 133 stress 0.05240172 
## Run 134 stress 0.05214966 
## Run 135 stress 0.05307785 
## Run 136 stress 0.05206284 
## Run 137 stress 0.1588525 
## Run 138 stress 0.05153054 
## ... Procrustes: rmse 0.01026537  max resid 0.08068602 
## Run 139 stress 0.05201695 
## Run 140 stress 0.05190443 
## ... Procrustes: rmse 0.01653525  max resid 0.09604784 
## Run 141 stress 0.05197757 
## Run 142 stress 0.05528191 
## Run 143 stress 0.05259099 
## Run 144 stress 0.05271106 
## Run 145 stress 0.05274797 
## Run 146 stress 0.05262119 
## Run 147 stress 0.05197011 
## Run 148 stress 0.05311436 
## Run 149 stress 0.05130192 
## ... New best solution
## ... Procrustes: rmse 0.009420044  max resid 0.06651491 
## Run 150 stress 0.05216552 
## Run 151 stress 0.06092379 
## Run 152 stress 0.05187237 
## Run 153 stress 0.05226914 
## Run 154 stress 0.05169271 
## ... Procrustes: rmse 0.008440097  max resid 0.08097014 
## Run 155 stress 0.05202477 
## Run 156 stress 0.05185182 
## Run 157 stress 0.05162456 
## ... Procrustes: rmse 0.007833095  max resid 0.08055947 
## Run 158 stress 0.05192652 
## Run 159 stress 0.05179228 
## ... Procrustes: rmse 0.01477473  max resid 0.09581911 
## Run 160 stress 0.05165168 
## ... Procrustes: rmse 0.01365529  max resid 0.09221101 
## Run 161 stress 0.05133465 
## ... Procrustes: rmse 0.00662813  max resid 0.04424624 
## Run 162 stress 0.0526142 
## Run 163 stress 0.05269498 
## Run 164 stress 0.05222327 
## Run 165 stress 0.05256909 
## Run 166 stress 0.05180691 
## Run 167 stress 0.05200818 
## Run 168 stress 0.05196344 
## Run 169 stress 0.05166769 
## ... Procrustes: rmse 0.008366909  max resid 0.05480997 
## Run 170 stress 0.05239025 
## Run 171 stress 0.05259763 
## Run 172 stress 0.052024 
## Run 173 stress 0.05136676 
## ... Procrustes: rmse 0.01048931  max resid 0.0666034 
## Run 174 stress 0.05472772 
## Run 175 stress 0.05235429 
## Run 176 stress 0.05242262 
## Run 177 stress 0.05185424 
## Run 178 stress 0.05204252 
## Run 179 stress 0.05212716 
## Run 180 stress 0.05155748 
## ... Procrustes: rmse 0.005810399  max resid 0.0328655 
## Run 181 stress 0.0519321 
## Run 182 stress 0.05262142 
## Run 183 stress 0.05213292 
## Run 184 stress 0.0526075 
## Run 185 stress 0.05212554 
## Run 186 stress 0.05209568 
## Run 187 stress 0.05187949 
## Run 188 stress 0.05260229 
## Run 189 stress 0.05217647 
## Run 190 stress 0.0517109 
## ... Procrustes: rmse 0.00748129  max resid 0.05143385 
## Run 191 stress 0.05219866 
## Run 192 stress 0.05170403 
## ... Procrustes: rmse 0.007570529  max resid 0.08111383 
## Run 193 stress 0.05202234 
## Run 194 stress 0.05169891 
## ... Procrustes: rmse 0.007634833  max resid 0.08102982 
## Run 195 stress 0.05226243 
## Run 196 stress 0.05274495 
## Run 197 stress 0.05198727 
## Run 198 stress 0.0527004 
## Run 199 stress 0.05265677 
## Run 200 stress 0.05206197 
## Run 201 stress 0.05164333 
## ... Procrustes: rmse 0.007610695  max resid 0.05755206 
## Run 202 stress 0.05199589 
## Run 203 stress 0.05277148 
## Run 204 stress 0.0523381 
## Run 205 stress 0.05190511 
## Run 206 stress 0.05260881 
## Run 207 stress 0.05187027 
## Run 208 stress 0.05209817 
## Run 209 stress 0.05182468 
## Run 210 stress 0.0522729 
## Run 211 stress 0.05190814 
## Run 212 stress 0.05160826 
## ... Procrustes: rmse 0.0149025  max resid 0.09301411 
## Run 213 stress 0.05260432 
## Run 214 stress 0.05196841 
## Run 215 stress 0.05210135 
## Run 216 stress 0.05147229 
## ... Procrustes: rmse 0.009834668  max resid 0.05614169 
## Run 217 stress 0.05209022 
## Run 218 stress 0.0520084 
## Run 219 stress 0.05194129 
## Run 220 stress 0.05188226 
## Run 221 stress 0.05196253 
## Run 222 stress 0.05283152 
## Run 223 stress 0.05154554 
## ... Procrustes: rmse 0.003850992  max resid 0.02937734 
## Run 224 stress 0.05209332 
## Run 225 stress 0.05239684 
## Run 226 stress 0.05279942 
## Run 227 stress 0.05268684 
## Run 228 stress 0.05164076 
## ... Procrustes: rmse 0.01210577  max resid 0.08125233 
## Run 229 stress 0.05178304 
## ... Procrustes: rmse 0.007503733  max resid 0.06559672 
## Run 230 stress 0.05195014 
## Run 231 stress 0.05189427 
## Run 232 stress 0.05141537 
## ... Procrustes: rmse 0.005800585  max resid 0.03774031 
## Run 233 stress 0.05174756 
## ... Procrustes: rmse 0.01312809  max resid 0.0564799 
## Run 234 stress 0.05207298 
## Run 235 stress 0.05189225 
## Run 236 stress 0.05396981 
## Run 237 stress 0.05166292 
## ... Procrustes: rmse 0.0112825  max resid 0.06091777 
## Run 238 stress 0.05214385 
## Run 239 stress 0.05179888 
## ... Procrustes: rmse 0.01162362  max resid 0.08801221 
## Run 240 stress 0.05225037 
## Run 241 stress 0.05189762 
## Run 242 stress 0.05181774 
## Run 243 stress 0.05193946 
## Run 244 stress 0.05186258 
## Run 245 stress 0.05210942 
## Run 246 stress 0.05222665 
## Run 247 stress 0.05262421 
## Run 248 stress 0.05179474 
## ... Procrustes: rmse 0.007036279  max resid 0.08266309 
## Run 249 stress 0.05221644 
## Run 250 stress 0.05231569 
## Run 251 stress 0.05154916 
## ... Procrustes: rmse 0.01313392  max resid 0.06572657 
## Run 252 stress 0.05138297 
## ... Procrustes: rmse 0.003434781  max resid 0.03159831 
## Run 253 stress 0.05205215 
## Run 254 stress 0.05298815 
## Run 255 stress 0.05192822 
## Run 256 stress 0.05262824 
## Run 257 stress 0.05154406 
## ... Procrustes: rmse 0.0125469  max resid 0.06779637 
## Run 258 stress 0.05204504 
## Run 259 stress 0.05169865 
## ... Procrustes: rmse 0.01051392  max resid 0.0683385 
## Run 260 stress 0.05344863 
## Run 261 stress 0.05211347 
## Run 262 stress 0.05239327 
## Run 263 stress 0.05187875 
## Run 264 stress 0.05205627 
## Run 265 stress 0.05193995 
## Run 266 stress 0.05132383 
## ... Procrustes: rmse 0.01176251  max resid 0.06790177 
## Run 267 stress 0.05205037 
## Run 268 stress 0.05232576 
## Run 269 stress 0.05180818 
## Run 270 stress 0.05196577 
## Run 271 stress 0.05230773 
## Run 272 stress 0.05240313 
## Run 273 stress 0.05181063 
## Run 274 stress 0.05173822 
## ... Procrustes: rmse 0.009364963  max resid 0.06048401 
## Run 275 stress 0.05234153 
## Run 276 stress 0.05184161 
## Run 277 stress 0.05254991 
## Run 278 stress 0.05260202 
## Run 279 stress 0.05213911 
## Run 280 stress 0.05255044 
## Run 281 stress 0.05213504 
## Run 282 stress 0.05315222 
## Run 283 stress 0.05159337 
## ... Procrustes: rmse 0.008336425  max resid 0.08068318 
## Run 284 stress 0.05283254 
## Run 285 stress 0.05179489 
## ... Procrustes: rmse 0.01100188  max resid 0.1089754 
## Run 286 stress 0.05199285 
## Run 287 stress 0.05204297 
## Run 288 stress 0.05227668 
## Run 289 stress 0.05182731 
## Run 290 stress 0.05150698 
## ... Procrustes: rmse 0.005051767  max resid 0.04546181 
## Run 291 stress 0.05211009 
## Run 292 stress 0.05150692 
## ... Procrustes: rmse 0.006162704  max resid 0.05566071 
## Run 293 stress 0.05202711 
## Run 294 stress 0.05157108 
## ... Procrustes: rmse 0.004360668  max resid 0.04336504 
## Run 295 stress 0.05235765 
## Run 296 stress 0.05151857 
## ... Procrustes: rmse 0.005747482  max resid 0.05643862 
## Run 297 stress 0.05232321 
## Run 298 stress 0.05231502 
## Run 299 stress 0.05196462 
## Run 300 stress 0.0516125 
## ... Procrustes: rmse 0.01071743  max resid 0.0539513 
## Run 301 stress 0.05175916 
## ... Procrustes: rmse 0.007321453  max resid 0.05620672 
## Run 302 stress 0.05170759 
## ... Procrustes: rmse 0.01061994  max resid 0.07082851 
## Run 303 stress 0.05204034 
## Run 304 stress 0.05186343 
## Run 305 stress 0.0523628 
## Run 306 stress 0.05262525 
## Run 307 stress 0.05255527 
## Run 308 stress 0.05183953 
## Run 309 stress 0.05221593 
## Run 310 stress 0.0514609 
## ... Procrustes: rmse 0.005174059  max resid 0.05653401 
## Run 311 stress 0.05239744 
## Run 312 stress 0.05188525 
## Run 313 stress 0.05213856 
## Run 314 stress 0.05251548 
## Run 315 stress 0.05253683 
## Run 316 stress 0.0518733 
## Run 317 stress 0.05165677 
## ... Procrustes: rmse 0.007722531  max resid 0.05150875 
## Run 318 stress 0.05247276 
## Run 319 stress 0.05271659 
## Run 320 stress 0.05201766 
## Run 321 stress 0.05208775 
## Run 322 stress 0.05225181 
## Run 323 stress 0.05195783 
## Run 324 stress 0.05234965 
## Run 325 stress 0.05327932 
## Run 326 stress 0.05245 
## Run 327 stress 0.05244918 
## Run 328 stress 0.0525808 
## Run 329 stress 0.05195396 
## Run 330 stress 0.05189018 
## Run 331 stress 0.05245329 
## Run 332 stress 0.0523345 
## Run 333 stress 0.05316089 
## Run 334 stress 0.05222692 
## Run 335 stress 0.05232414 
## Run 336 stress 0.05207049 
## Run 337 stress 0.05203751 
## Run 338 stress 0.0518199 
## Run 339 stress 0.05190676 
## Run 340 stress 0.05213057 
## Run 341 stress 0.05221408 
## Run 342 stress 0.05238887 
## Run 343 stress 0.05247178 
## Run 344 stress 0.05159304 
## ... Procrustes: rmse 0.01579803  max resid 0.09540393 
## Run 345 stress 0.05243119 
## Run 346 stress 0.0526986 
## Run 347 stress 0.0516651 
## ... Procrustes: rmse 0.01243989  max resid 0.06380442 
## Run 348 stress 0.05269837 
## Run 349 stress 0.05211855 
## Run 350 stress 0.05191195 
## Run 351 stress 0.05209208 
## Run 352 stress 0.05196982 
## Run 353 stress 0.0523478 
## Run 354 stress 0.05190766 
## Run 355 stress 0.05147101 
## ... Procrustes: rmse 0.01146627  max resid 0.06621021 
## Run 356 stress 0.05200149 
## Run 357 stress 0.05197489 
## Run 358 stress 0.05255547 
## Run 359 stress 0.0514068 
## ... Procrustes: rmse 0.007343754  max resid 0.05638087 
## Run 360 stress 0.0516815 
## ... Procrustes: rmse 0.01301229  max resid 0.06717575 
## Run 361 stress 0.05243193 
## Run 362 stress 0.05171217 
## ... Procrustes: rmse 0.008392411  max resid 0.08430533 
## Run 363 stress 0.05276512 
## Run 364 stress 0.05233601 
## Run 365 stress 0.05287493 
## Run 366 stress 0.05208771 
## Run 367 stress 0.05196069 
## Run 368 stress 0.05181372 
## Run 369 stress 0.05172585 
## ... Procrustes: rmse 0.0122105  max resid 0.09009095 
## Run 370 stress 0.05192807 
## Run 371 stress 0.05139325 
## ... Procrustes: rmse 0.01074066  max resid 0.06914658 
## Run 372 stress 0.05197258 
## Run 373 stress 0.05249315 
## Run 374 stress 0.05280868 
## Run 375 stress 0.05213104 
## Run 376 stress 0.05172128 
## ... Procrustes: rmse 0.01380411  max resid 0.0634405 
## Run 377 stress 0.05198449 
## Run 378 stress 0.05219141 
## Run 379 stress 0.05187482 
## Run 380 stress 0.05261105 
## Run 381 stress 0.05230957 
## Run 382 stress 0.05242936 
## Run 383 stress 0.05218908 
## Run 384 stress 0.05278982 
## Run 385 stress 0.05203896 
## Run 386 stress 0.05182172 
## Run 387 stress 0.05172804 
## ... Procrustes: rmse 0.01075652  max resid 0.07997147 
## Run 388 stress 0.05213795 
## Run 389 stress 0.05267033 
## Run 390 stress 0.05256589 
## Run 391 stress 0.05252238 
## Run 392 stress 0.05294169 
## Run 393 stress 0.05166353 
## ... Procrustes: rmse 0.009640076  max resid 0.0805646 
## Run 394 stress 0.05265064 
## Run 395 stress 0.05210914 
## Run 396 stress 0.05277462 
## Run 397 stress 0.05199318 
## Run 398 stress 0.05256672 
## Run 399 stress 0.05244913 
## Run 400 stress 0.05241933 
## Run 401 stress 0.05249683 
## Run 402 stress 0.05211584 
## Run 403 stress 0.05208034 
## Run 404 stress 0.0519028 
## Run 405 stress 0.05260969 
## Run 406 stress 0.05240081 
## Run 407 stress 0.05216231 
## Run 408 stress 0.05204783 
## Run 409 stress 0.05237292 
## Run 410 stress 0.05196696 
## Run 411 stress 0.05252947 
## Run 412 stress 0.05234242 
## Run 413 stress 0.05212532 
## Run 414 stress 0.05146441 
## ... Procrustes: rmse 0.009886489  max resid 0.0664155 
## Run 415 stress 0.05238622 
## Run 416 stress 0.05200639 
## Run 417 stress 0.05244563 
## Run 418 stress 0.05202958 
## Run 419 stress 0.05246067 
## Run 420 stress 0.05202178 
## Run 421 stress 0.05169798 
## ... Procrustes: rmse 0.01108701  max resid 0.05611431 
## Run 422 stress 0.05169263 
## ... Procrustes: rmse 0.01379526  max resid 0.1107381 
## Run 423 stress 0.05173359 
## ... Procrustes: rmse 0.005738355  max resid 0.05868852 
## Run 424 stress 0.05175254 
## ... Procrustes: rmse 0.0111978  max resid 0.08095484 
## Run 425 stress 0.05200365 
## Run 426 stress 0.05199945 
## Run 427 stress 0.05239743 
## Run 428 stress 0.05166259 
## ... Procrustes: rmse 0.007357671  max resid 0.05763373 
## Run 429 stress 0.05261105 
## Run 430 stress 0.05180243 
## Run 431 stress 0.05159162 
## ... Procrustes: rmse 0.0069855  max resid 0.08100734 
## Run 432 stress 0.05198038 
## Run 433 stress 0.0522571 
## Run 434 stress 0.05202392 
## Run 435 stress 0.05185538 
## Run 436 stress 0.05183324 
## Run 437 stress 0.05264108 
## Run 438 stress 0.05203401 
## Run 439 stress 0.0525815 
## Run 440 stress 0.0516681 
## ... Procrustes: rmse 0.01294569  max resid 0.06732919 
## Run 441 stress 0.05166076 
## ... Procrustes: rmse 0.01109002  max resid 0.05919699 
## Run 442 stress 0.05190606 
## Run 443 stress 0.05167253 
## ... Procrustes: rmse 0.01059842  max resid 0.08071784 
## Run 444 stress 0.05172003 
## ... Procrustes: rmse 0.009355856  max resid 0.08266557 
## Run 445 stress 0.05158926 
## ... Procrustes: rmse 0.006839033  max resid 0.05436398 
## Run 446 stress 0.05160412 
## ... Procrustes: rmse 0.01299558  max resid 0.06831594 
## Run 447 stress 0.05211302 
## Run 448 stress 0.05235514 
## Run 449 stress 0.05188978 
## Run 450 stress 0.0520379 
## Run 451 stress 0.05198393 
## Run 452 stress 0.05264782 
## Run 453 stress 0.05212006 
## Run 454 stress 0.0521124 
## Run 455 stress 0.05189601 
## Run 456 stress 0.05206585 
## Run 457 stress 0.05183198 
## Run 458 stress 0.0519786 
## Run 459 stress 0.052973 
## Run 460 stress 0.05297469 
## Run 461 stress 0.05313024 
## Run 462 stress 0.05332946 
## Run 463 stress 0.05164184 
## ... Procrustes: rmse 0.006067054  max resid 0.04272103 
## Run 464 stress 0.05214084 
## Run 465 stress 0.0520936 
## Run 466 stress 0.05168817 
## ... Procrustes: rmse 0.01348752  max resid 0.09121813 
## Run 467 stress 0.05212413 
## Run 468 stress 0.05197788 
## Run 469 stress 0.05207733 
## Run 470 stress 0.05329564 
## Run 471 stress 0.05191375 
## Run 472 stress 0.05203061 
## Run 473 stress 0.05214483 
## Run 474 stress 0.05149646 
## ... Procrustes: rmse 0.005104391  max resid 0.02938734 
## Run 475 stress 0.05149674 
## ... Procrustes: rmse 0.008446832  max resid 0.05471366 
## Run 476 stress 0.0527866 
## Run 477 stress 0.05272069 
## Run 478 stress 0.05227624 
## Run 479 stress 0.05187872 
## Run 480 stress 0.05332746 
## Run 481 stress 0.0521761 
## Run 482 stress 0.05232144 
## Run 483 stress 0.05212288 
## Run 484 stress 0.05274839 
## Run 485 stress 0.07614566 
## Run 486 stress 0.0517595 
## ... Procrustes: rmse 0.006597441  max resid 0.05717679 
## Run 487 stress 0.05144006 
## ... Procrustes: rmse 0.01104536  max resid 0.06812274 
## Run 488 stress 0.05219623 
## Run 489 stress 0.05253631 
## Run 490 stress 0.05212192 
## Run 491 stress 0.05173835 
## ... Procrustes: rmse 0.01002432  max resid 0.1070474 
## Run 492 stress 0.05184206 
## Run 493 stress 0.05201286 
## Run 494 stress 0.05163016 
## ... Procrustes: rmse 0.01110234  max resid 0.06837464 
## Run 495 stress 0.05325712 
## Run 496 stress 0.05229185 
## Run 497 stress 0.05255563 
## Run 498 stress 0.0520531 
## Run 499 stress 0.05226361 
## Run 500 stress 0.05170044 
## ... Procrustes: rmse 0.01345488  max resid 0.1117179 
## Run 501 stress 0.05148789 
## ... Procrustes: rmse 0.004649672  max resid 0.04509898 
## Run 502 stress 0.05220339 
## Run 503 stress 0.0519401 
## Run 504 stress 0.05209208 
## Run 505 stress 0.05214798 
## Run 506 stress 0.05209631 
## Run 507 stress 0.05257854 
## Run 508 stress 0.05175949 
## ... Procrustes: rmse 0.01368771  max resid 0.1112687 
## Run 509 stress 0.05207231 
## Run 510 stress 0.05193926 
## Run 511 stress 0.05149131 
## ... Procrustes: rmse 0.01224318  max resid 0.0672308 
## Run 512 stress 0.05215479 
## Run 513 stress 0.05230804 
## Run 514 stress 0.05186145 
## Run 515 stress 0.05183526 
## Run 516 stress 0.05181713 
## Run 517 stress 0.05253537 
## Run 518 stress 0.05178997 
## ... Procrustes: rmse 0.0161756  max resid 0.0809829 
## Run 519 stress 0.05319975 
## Run 520 stress 0.0515626 
## ... Procrustes: rmse 0.005680332  max resid 0.0555557 
## Run 521 stress 0.05196879 
## Run 522 stress 0.05237338 
## Run 523 stress 0.05215497 
## Run 524 stress 0.05247354 
## Run 525 stress 0.05195665 
## Run 526 stress 0.0519289 
## Run 527 stress 0.05181067 
## Run 528 stress 0.05214681 
## Run 529 stress 0.05211643 
## Run 530 stress 0.05170988 
## ... Procrustes: rmse 0.008314807  max resid 0.05504321 
## Run 531 stress 0.05182063 
## Run 532 stress 0.05247334 
## Run 533 stress 0.05393544 
## Run 534 stress 0.0520452 
## Run 535 stress 0.0525733 
## Run 536 stress 0.05197437 
## Run 537 stress 0.05240219 
## Run 538 stress 0.05213871 
## Run 539 stress 0.05214908 
## Run 540 stress 0.05153652 
## ... Procrustes: rmse 0.01075068  max resid 0.06977424 
## Run 541 stress 0.05165449 
## ... Procrustes: rmse 0.00605523  max resid 0.05632013 
## Run 542 stress 0.05204893 
## Run 543 stress 0.05200132 
## Run 544 stress 0.05143495 
## ... Procrustes: rmse 0.005212687  max resid 0.05559499 
## Run 545 stress 0.05169045 
## ... Procrustes: rmse 0.00626594  max resid 0.05861659 
## Run 546 stress 0.05176045 
## ... Procrustes: rmse 0.01307482  max resid 0.08739997 
## Run 547 stress 0.05236138 
## Run 548 stress 0.05245739 
## Run 549 stress 0.05217945 
## Run 550 stress 0.05310136 
## Run 551 stress 0.05148223 
## ... Procrustes: rmse 0.009555707  max resid 0.07003456 
## Run 552 stress 0.05220753 
## Run 553 stress 0.0526373 
## Run 554 stress 0.05254341 
## Run 555 stress 0.0522023 
## Run 556 stress 0.05217434 
## Run 557 stress 0.05265205 
## Run 558 stress 0.05258947 
## Run 559 stress 0.05190459 
## Run 560 stress 0.05214356 
## Run 561 stress 0.05291861 
## Run 562 stress 0.05218194 
## Run 563 stress 0.0517438 
## ... Procrustes: rmse 0.0111656  max resid 0.08548785 
## Run 564 stress 0.05153522 
## ... Procrustes: rmse 0.008407871  max resid 0.05617668 
## Run 565 stress 0.05315163 
## Run 566 stress 0.05240387 
## Run 567 stress 0.05221808 
## Run 568 stress 0.05300087 
## Run 569 stress 0.05168064 
## ... Procrustes: rmse 0.016217  max resid 0.0814385 
## Run 570 stress 0.05193266 
## Run 571 stress 0.05198519 
## Run 572 stress 0.05257081 
## Run 573 stress 0.05284988 
## Run 574 stress 0.05189879 
## Run 575 stress 0.0520186 
## Run 576 stress 0.05194329 
## Run 577 stress 0.052763 
## Run 578 stress 0.05200199 
## Run 579 stress 0.05204513 
## Run 580 stress 0.05187153 
## Run 581 stress 0.05199708 
## Run 582 stress 0.05203571 
## Run 583 stress 0.0532065 
## Run 584 stress 0.05237767 
## Run 585 stress 0.05246151 
## Run 586 stress 0.05294641 
## Run 587 stress 0.05274816 
## Run 588 stress 0.05238516 
## Run 589 stress 0.05213312 
## Run 590 stress 0.05240922 
## Run 591 stress 0.05284287 
## Run 592 stress 0.0518654 
## Run 593 stress 0.05260719 
## Run 594 stress 0.05304073 
## Run 595 stress 0.05247776 
## Run 596 stress 0.05312629 
## Run 597 stress 0.05166189 
## ... Procrustes: rmse 0.01230352  max resid 0.08794161 
## Run 598 stress 0.0515847 
## ... Procrustes: rmse 0.01161353  max resid 0.08686007 
## Run 599 stress 0.05258522 
## Run 600 stress 0.05219726 
## Run 601 stress 0.05209527 
## Run 602 stress 0.05210965 
## Run 603 stress 0.05195247 
## Run 604 stress 0.05218755 
## Run 605 stress 0.05192349 
## Run 606 stress 0.05235457 
## Run 607 stress 0.05264219 
## Run 608 stress 0.05218132 
## Run 609 stress 0.05225116 
## Run 610 stress 0.05245833 
## Run 611 stress 0.0516683 
## ... Procrustes: rmse 0.00998209  max resid 0.1084054 
## Run 612 stress 0.05172535 
## ... Procrustes: rmse 0.01067848  max resid 0.08138361 
## Run 613 stress 0.05142139 
## ... Procrustes: rmse 0.007638469  max resid 0.05360962 
## Run 614 stress 0.05221834 
## Run 615 stress 0.0520952 
## Run 616 stress 0.05232415 
## Run 617 stress 0.05247248 
## Run 618 stress 0.0536041 
## Run 619 stress 0.05382789 
## Run 620 stress 0.05213548 
## Run 621 stress 0.05184915 
## Run 622 stress 0.05155604 
## ... Procrustes: rmse 0.005614318  max resid 0.05500893 
## Run 623 stress 0.05256033 
## Run 624 stress 0.05184821 
## Run 625 stress 0.05207591 
## Run 626 stress 0.05243212 
## Run 627 stress 0.05152441 
## ... Procrustes: rmse 0.0111691  max resid 0.0681276 
## Run 628 stress 0.05265431 
## Run 629 stress 0.05250368 
## Run 630 stress 0.05194414 
## Run 631 stress 0.05181896 
## Run 632 stress 0.05184942 
## Run 633 stress 0.05271821 
## Run 634 stress 0.05231288 
## Run 635 stress 0.05197251 
## Run 636 stress 0.05228964 
## Run 637 stress 0.05226651 
## Run 638 stress 0.05184406 
## Run 639 stress 0.05176327 
## ... Procrustes: rmse 0.01030687  max resid 0.0880294 
## Run 640 stress 0.05234366 
## Run 641 stress 0.0522149 
## Run 642 stress 0.05190034 
## Run 643 stress 0.05208669 
## Run 644 stress 0.05218486 
## Run 645 stress 0.05229841 
## Run 646 stress 0.05201225 
## Run 647 stress 0.05183703 
## Run 648 stress 0.05293959 
## Run 649 stress 0.05164543 
## ... Procrustes: rmse 0.009153016  max resid 0.1061847 
## Run 650 stress 0.05199184 
## Run 651 stress 0.05168175 
## ... Procrustes: rmse 0.01275428  max resid 0.1130649 
## Run 652 stress 0.05182741 
## Run 653 stress 0.0524441 
## Run 654 stress 0.05196304 
## Run 655 stress 0.0525819 
## Run 656 stress 0.05169614 
## ... Procrustes: rmse 0.01382487  max resid 0.08107953 
## Run 657 stress 0.05196939 
## Run 658 stress 0.05232762 
## Run 659 stress 0.05166764 
## ... Procrustes: rmse 0.01644344  max resid 0.08155944 
## Run 660 stress 0.05216201 
## Run 661 stress 0.05195777 
## Run 662 stress 0.05226498 
## Run 663 stress 0.05196831 
## Run 664 stress 0.05161427 
## ... Procrustes: rmse 0.008864613  max resid 0.08158466 
## Run 665 stress 0.05335199 
## Run 666 stress 0.05181504 
## Run 667 stress 0.05307427 
## Run 668 stress 0.05167165 
## ... Procrustes: rmse 0.01563232  max resid 0.06599394 
## Run 669 stress 0.05298893 
## Run 670 stress 0.05266118 
## Run 671 stress 0.05174072 
## ... Procrustes: rmse 0.01459544  max resid 0.06849451 
## Run 672 stress 0.05210513 
## Run 673 stress 0.05206713 
## Run 674 stress 0.05222625 
## Run 675 stress 0.0523645 
## Run 676 stress 0.05246677 
## Run 677 stress 0.05198009 
## Run 678 stress 0.05169877 
## ... Procrustes: rmse 0.01047217  max resid 0.06818499 
## Run 679 stress 0.05204794 
## Run 680 stress 0.05178328 
## ... Procrustes: rmse 0.01508768  max resid 0.06789386 
## Run 681 stress 0.05222573 
## Run 682 stress 0.05214807 
## Run 683 stress 0.05156233 
## ... Procrustes: rmse 0.01492811  max resid 0.08093666 
## Run 684 stress 0.05176217 
## ... Procrustes: rmse 0.008129966  max resid 0.08088883 
## Run 685 stress 0.05309681 
## Run 686 stress 0.05236185 
## Run 687 stress 0.05200556 
## Run 688 stress 0.05947997 
## Run 689 stress 0.05202675 
## Run 690 stress 0.05252511 
## Run 691 stress 0.0515553 
## ... Procrustes: rmse 0.008044929  max resid 0.06578439 
## Run 692 stress 0.05219315 
## Run 693 stress 0.05255944 
## Run 694 stress 0.05151184 
## ... Procrustes: rmse 0.007686081  max resid 0.05739469 
## Run 695 stress 0.05177282 
## ... Procrustes: rmse 0.009092528  max resid 0.104843 
## Run 696 stress 0.05197364 
## Run 697 stress 0.05150253 
## ... Procrustes: rmse 0.01237613  max resid 0.06773998 
## Run 698 stress 0.05255575 
## Run 699 stress 0.05239507 
## Run 700 stress 0.05165482 
## ... Procrustes: rmse 0.01263973  max resid 0.1033608 
## Run 701 stress 0.05144599 
## ... Procrustes: rmse 0.01047826  max resid 0.05617866 
## Run 702 stress 0.0520296 
## Run 703 stress 0.05205005 
## Run 704 stress 0.05281328 
## Run 705 stress 0.05206634 
## Run 706 stress 0.0518632 
## Run 707 stress 0.05198709 
## Run 708 stress 0.05248543 
## Run 709 stress 0.05254994 
## Run 710 stress 0.05217932 
## Run 711 stress 0.05173229 
## ... Procrustes: rmse 0.009187118  max resid 0.1056781 
## Run 712 stress 0.052102 
## Run 713 stress 0.05202711 
## Run 714 stress 0.05325205 
## Run 715 stress 0.05215928 
## Run 716 stress 0.05144994 
## ... Procrustes: rmse 0.008943258  max resid 0.05669313 
## Run 717 stress 0.05270825 
## Run 718 stress 0.05222832 
## Run 719 stress 0.05337609 
## Run 720 stress 0.05229755 
## Run 721 stress 0.05228903 
## Run 722 stress 0.05162162 
## ... Procrustes: rmse 0.00953746  max resid 0.08121116 
## Run 723 stress 0.05259028 
## Run 724 stress 0.05283618 
## Run 725 stress 0.05347564 
## Run 726 stress 0.05253557 
## Run 727 stress 0.05261116 
## Run 728 stress 0.05247305 
## Run 729 stress 0.05172805 
## ... Procrustes: rmse 0.01029139  max resid 0.05665291 
## Run 730 stress 0.05195586 
## Run 731 stress 0.05208903 
## Run 732 stress 0.05242387 
## Run 733 stress 0.05227761 
## Run 734 stress 0.05300698 
## Run 735 stress 0.05160902 
## ... Procrustes: rmse 0.006979134  max resid 0.08126217 
## Run 736 stress 0.05238829 
## Run 737 stress 0.05244665 
## Run 738 stress 0.05208497 
## Run 739 stress 0.05210476 
## Run 740 stress 0.05250838 
## Run 741 stress 0.05184242 
## Run 742 stress 0.05195593 
## Run 743 stress 0.0529109 
## Run 744 stress 0.05238403 
## Run 745 stress 0.05203824 
## Run 746 stress 0.05209093 
## Run 747 stress 0.0520824 
## Run 748 stress 0.05180532 
## Run 749 stress 0.0522739 
## Run 750 stress 0.05189322 
## Run 751 stress 0.05205815 
## Run 752 stress 0.05163112 
## ... Procrustes: rmse 0.007169502  max resid 0.0807013 
## Run 753 stress 0.05210849 
## Run 754 stress 0.05547279 
## Run 755 stress 0.05205475 
## Run 756 stress 0.05216658 
## Run 757 stress 0.05244184 
## Run 758 stress 0.05147131 
## ... Procrustes: rmse 0.009891134  max resid 0.0587331 
## Run 759 stress 0.05173132 
## ... Procrustes: rmse 0.007228269  max resid 0.08155591 
## Run 760 stress 0.05186283 
## Run 761 stress 0.05182629 
## Run 762 stress 0.05190734 
## Run 763 stress 0.05214143 
## Run 764 stress 0.05207132 
## Run 765 stress 0.0526927 
## Run 766 stress 0.05239997 
## Run 767 stress 0.05181191 
## Run 768 stress 0.05282668 
## Run 769 stress 0.05519268 
## Run 770 stress 0.05212706 
## Run 771 stress 0.0526007 
## Run 772 stress 0.05141908 
## ... Procrustes: rmse 0.005406844  max resid 0.03117821 
## Run 773 stress 0.05179484 
## ... Procrustes: rmse 0.01486782  max resid 0.1117621 
## Run 774 stress 0.05180255 
## Run 775 stress 0.05285035 
## Run 776 stress 0.05182163 
## Run 777 stress 0.05201629 
## Run 778 stress 0.05181225 
## Run 779 stress 0.05188036 
## Run 780 stress 0.05200165 
## Run 781 stress 0.05285942 
## Run 782 stress 0.05230374 
## Run 783 stress 0.05136316 
## ... Procrustes: rmse 0.01051373  max resid 0.06852599 
## Run 784 stress 0.05205859 
## Run 785 stress 0.05151196 
## ... Procrustes: rmse 0.005831938  max resid 0.03998562 
## Run 786 stress 0.05200017 
## Run 787 stress 0.05198156 
## Run 788 stress 0.05263641 
## Run 789 stress 0.0519695 
## Run 790 stress 0.05180208 
## Run 791 stress 0.05223343 
## Run 792 stress 0.05155985 
## ... Procrustes: rmse 0.00817607  max resid 0.08390153 
## Run 793 stress 0.05200336 
## Run 794 stress 0.05237207 
## Run 795 stress 0.05268555 
## Run 796 stress 0.05280496 
## Run 797 stress 0.05240595 
## Run 798 stress 0.05180188 
## ... Procrustes: rmse 0.01517109  max resid 0.1098374 
## Run 799 stress 0.05223371 
## Run 800 stress 0.05295784 
## Run 801 stress 0.05194545 
## Run 802 stress 0.05247463 
## Run 803 stress 0.05237692 
## Run 804 stress 0.0523918 
## Run 805 stress 0.05227612 
## Run 806 stress 0.05204051 
## Run 807 stress 0.05145715 
## ... Procrustes: rmse 0.009397585  max resid 0.05747435 
## Run 808 stress 0.05188434 
## Run 809 stress 0.05279965 
## Run 810 stress 0.05194196 
## Run 811 stress 0.05206123 
## Run 812 stress 0.05326904 
## Run 813 stress 0.0524096 
## Run 814 stress 0.05334168 
## Run 815 stress 0.05203738 
## Run 816 stress 0.05165162 
## ... Procrustes: rmse 0.01117561  max resid 0.06698546 
## Run 817 stress 0.05220001 
## Run 818 stress 0.05253028 
## Run 819 stress 0.05151985 
## ... Procrustes: rmse 0.01184715  max resid 0.06892708 
## Run 820 stress 0.05344519 
## Run 821 stress 0.05269845 
## Run 822 stress 0.05214946 
## Run 823 stress 0.05169129 
## ... Procrustes: rmse 0.007937332  max resid 0.08170386 
## Run 824 stress 0.05207656 
## Run 825 stress 0.05188755 
## Run 826 stress 0.0527015 
## Run 827 stress 0.05162992 
## ... Procrustes: rmse 0.01779586  max resid 0.08149082 
## Run 828 stress 0.05235891 
## Run 829 stress 0.05195163 
## Run 830 stress 0.05153261 
## ... Procrustes: rmse 0.01069119  max resid 0.06001507 
## Run 831 stress 0.05221001 
## Run 832 stress 0.05166697 
## ... Procrustes: rmse 0.01362076  max resid 0.06650411 
## Run 833 stress 0.0528684 
## Run 834 stress 0.05158948 
## ... Procrustes: rmse 0.008888198  max resid 0.05655072 
## Run 835 stress 0.05314511 
## Run 836 stress 0.05190461 
## Run 837 stress 0.05235394 
## Run 838 stress 0.05133124 
## ... Procrustes: rmse 0.00476955  max resid 0.03198773 
## Run 839 stress 0.05219562 
## Run 840 stress 0.05193752 
## Run 841 stress 0.05180147 
## ... Procrustes: rmse 0.01627357  max resid 0.09510612 
## Run 842 stress 0.05243124 
## Run 843 stress 0.05182517 
## Run 844 stress 0.05162061 
## ... Procrustes: rmse 0.01037251  max resid 0.08122818 
## Run 845 stress 0.0519128 
## Run 846 stress 0.05211276 
## Run 847 stress 0.06253091 
## Run 848 stress 0.05224398 
## Run 849 stress 0.05165567 
## ... Procrustes: rmse 0.0133885  max resid 0.111746 
## Run 850 stress 0.05213783 
## Run 851 stress 0.05184782 
## Run 852 stress 0.05229552 
## Run 853 stress 0.05177622 
## ... Procrustes: rmse 0.01016928  max resid 0.06876038 
## Run 854 stress 0.05190829 
## Run 855 stress 0.05230033 
## Run 856 stress 0.05171695 
## ... Procrustes: rmse 0.009203308  max resid 0.1069098 
## Run 857 stress 0.05240601 
## Run 858 stress 0.05243622 
## Run 859 stress 0.05235035 
## Run 860 stress 0.05257038 
## Run 861 stress 0.05222486 
## Run 862 stress 0.05257079 
## Run 863 stress 0.0528153 
## Run 864 stress 0.0518912 
## Run 865 stress 0.05234212 
## Run 866 stress 0.05198539 
## Run 867 stress 0.05165475 
## ... Procrustes: rmse 0.01158886  max resid 0.0677949 
## Run 868 stress 0.05161933 
## ... Procrustes: rmse 0.01775656  max resid 0.08074949 
## Run 869 stress 0.05177631 
## ... Procrustes: rmse 0.009405688  max resid 0.0649911 
## Run 870 stress 0.05259283 
## Run 871 stress 0.05275244 
## Run 872 stress 0.0519749 
## Run 873 stress 0.05174751 
## ... Procrustes: rmse 0.01160828  max resid 0.1076964 
## Run 874 stress 0.05242828 
## Run 875 stress 0.05211589 
## Run 876 stress 0.05242474 
## Run 877 stress 0.05225109 
## Run 878 stress 0.05174005 
## ... Procrustes: rmse 0.01565061  max resid 0.0810388 
## Run 879 stress 0.05254163 
## Run 880 stress 0.05209706 
## Run 881 stress 0.05165752 
## ... Procrustes: rmse 0.009611092  max resid 0.05251407 
## Run 882 stress 0.05236293 
## Run 883 stress 0.05203123 
## Run 884 stress 0.0519891 
## Run 885 stress 0.0522402 
## Run 886 stress 0.05176059 
## ... Procrustes: rmse 0.009364357  max resid 0.08275735 
## Run 887 stress 0.0518098 
## Run 888 stress 0.05227428 
## Run 889 stress 0.05218043 
## Run 890 stress 0.05239256 
## Run 891 stress 0.05165535 
## ... Procrustes: rmse 0.01314759  max resid 0.1124427 
## Run 892 stress 0.0524237 
## Run 893 stress 0.05215151 
## Run 894 stress 0.05208477 
## Run 895 stress 0.05172939 
## ... Procrustes: rmse 0.01350023  max resid 0.06594118 
## Run 896 stress 0.0520355 
## Run 897 stress 0.05185103 
## Run 898 stress 0.0519198 
## Run 899 stress 0.05221221 
## Run 900 stress 0.05181912 
## Run 901 stress 0.05265918 
## Run 902 stress 0.05249186 
## Run 903 stress 0.0516235 
## ... Procrustes: rmse 0.01389216  max resid 0.06630386 
## Run 904 stress 0.05166831 
## ... Procrustes: rmse 0.01294281  max resid 0.11114 
## Run 905 stress 0.05194362 
## Run 906 stress 0.05170981 
## ... Procrustes: rmse 0.01016398  max resid 0.08416746 
## Run 907 stress 0.05202785 
## Run 908 stress 0.05241201 
## Run 909 stress 0.05236246 
## Run 910 stress 0.05225238 
## Run 911 stress 0.05218375 
## Run 912 stress 0.05171777 
## ... Procrustes: rmse 0.0147586  max resid 0.1128544 
## Run 913 stress 0.05176 
## ... Procrustes: rmse 0.01696581  max resid 0.1123442 
## Run 914 stress 0.05189768 
## Run 915 stress 0.05219638 
## Run 916 stress 0.05186358 
## Run 917 stress 0.05190173 
## Run 918 stress 0.05175088 
## ... Procrustes: rmse 0.01183997  max resid 0.0688367 
## Run 919 stress 0.05184698 
## Run 920 stress 0.05135055 
## ... Procrustes: rmse 0.01070627  max resid 0.06686356 
## Run 921 stress 0.05170351 
## ... Procrustes: rmse 0.01027981  max resid 0.062005 
## Run 922 stress 0.05189014 
## Run 923 stress 0.0516431 
## ... Procrustes: rmse 0.007188579  max resid 0.0811777 
## Run 924 stress 0.052352 
## Run 925 stress 0.05166831 
## ... Procrustes: rmse 0.006519027  max resid 0.05888946 
## Run 926 stress 0.05163601 
## ... Procrustes: rmse 0.008711307  max resid 0.08215292 
## Run 927 stress 0.05257396 
## Run 928 stress 0.052573 
## Run 929 stress 0.05240377 
## Run 930 stress 0.05348603 
## Run 931 stress 0.05211573 
## Run 932 stress 0.05178057 
## ... Procrustes: rmse 0.007930483  max resid 0.06000639 
## Run 933 stress 0.05182756 
## Run 934 stress 0.05243387 
## Run 935 stress 0.05182534 
## Run 936 stress 0.05213081 
## Run 937 stress 0.05195753 
## Run 938 stress 0.051587 
## ... Procrustes: rmse 0.01360811  max resid 0.06876188 
## Run 939 stress 0.05160185 
## ... Procrustes: rmse 0.01148304  max resid 0.0651045 
## Run 940 stress 0.0516082 
## ... Procrustes: rmse 0.008885428  max resid 0.1053834 
## Run 941 stress 0.0523558 
## Run 942 stress 0.05218319 
## Run 943 stress 0.05216471 
## Run 944 stress 0.0522504 
## Run 945 stress 0.05172309 
## ... Procrustes: rmse 0.01186753  max resid 0.08954336 
## Run 946 stress 0.05176019 
## ... Procrustes: rmse 0.009318147  max resid 0.08904574 
## Run 947 stress 0.05221494 
## Run 948 stress 0.05174481 
## ... Procrustes: rmse 0.009078731  max resid 0.0496792 
## Run 949 stress 0.05220718 
## Run 950 stress 0.05260851 
## Run 951 stress 0.05219874 
## Run 952 stress 0.05198063 
## Run 953 stress 0.0521985 
## Run 954 stress 0.05425346 
## Run 955 stress 0.05554112 
## Run 956 stress 0.05222641 
## Run 957 stress 0.05206117 
## Run 958 stress 0.05253036 
## Run 959 stress 0.05258109 
## Run 960 stress 0.05350892 
## Run 961 stress 0.05184291 
## Run 962 stress 0.05235765 
## Run 963 stress 0.05207101 
## Run 964 stress 0.0515413 
## ... Procrustes: rmse 0.005653746  max resid 0.08118816 
## Run 965 stress 0.05352027 
## Run 966 stress 0.05273308 
## Run 967 stress 0.0522876 
## Run 968 stress 0.0517126 
## ... Procrustes: rmse 0.01001016  max resid 0.05652748 
## Run 969 stress 0.05279329 
## Run 970 stress 0.05295407 
## Run 971 stress 0.0518892 
## Run 972 stress 0.05295531 
## Run 973 stress 0.05225031 
## Run 974 stress 0.05226218 
## Run 975 stress 0.05267683 
## Run 976 stress 0.05306959 
## Run 977 stress 0.05227773 
## Run 978 stress 0.05200903 
## Run 979 stress 0.05174823 
## ... Procrustes: rmse 0.01188595  max resid 0.08042796 
## Run 980 stress 0.05232846 
## Run 981 stress 0.05169423 
## ... Procrustes: rmse 0.009411745  max resid 0.1096399 
## Run 982 stress 0.05223353 
## Run 983 stress 0.05279913 
## Run 984 stress 0.05231152 
## Run 985 stress 0.0519117 
## Run 986 stress 0.05224774 
## Run 987 stress 0.05249763 
## Run 988 stress 0.05200162 
## Run 989 stress 0.05156312 
## ... Procrustes: rmse 0.0111245  max resid 0.07994323 
## Run 990 stress 0.05188507 
## Run 991 stress 0.0518685 
## Run 992 stress 0.05139854 
## ... Procrustes: rmse 0.008423111  max resid 0.06807775 
## Run 993 stress 0.05182883 
## Run 994 stress 0.05163979 
## ... Procrustes: rmse 0.01315385  max resid 0.063419 
## Run 995 stress 0.05238619 
## Run 996 stress 0.05141112 
## ... Procrustes: rmse 0.006175407  max resid 0.04499948 
## Run 997 stress 0.05229017 
## Run 998 stress 0.05249373 
## Run 999 stress 0.05196249 
## Run 1000 stress 0.05192376 
## *** Best solution was not repeated -- monoMDS stopping criteria:
##   1000: no. of iterations >= maxit
# Save distance objects
save(jac.dist, jac.nmds, jac.pcoa, file = "R_objects/jac.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())

2.2.5.1 SUBSETS

2.2.5.1.1 Feces
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day %in% c("d0","d2","d4","d8"))

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate UniFrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f0248.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f0.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f2.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f4.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day %in% c("d0","d8"))

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f08.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.5.1.2 Feces, Cecum, Ileum
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.fceil8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8" & material == "Cecum")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.ce8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, day == "d8" & material == "Ileum")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate wUnifrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.il8.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.5.1.3 Feces non-Vancomycin and Vancomycin
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f0_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d0" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f0_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f2_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d2" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f2_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f4_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d4" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f4_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.f8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.5.1.4 Cecum & Ileum non-Vancomycin and Vancomycin
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Cecum" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.ce8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Cecum" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.ce8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Ileum" & day == "d8" & van == "ctrl")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.il8_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Ileum" & day == "d8" & van == "van")

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.il8_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
2.2.5.1.5 Feces diversity over time
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "CTRL") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.feces_ctrl.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "PFOS") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.feces_pfos.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "VAN") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.feces_van.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())
params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/jac.RData")

tmp.dist <- as.matrix(jac.dist)
# Create subset
phy.sub <- subset_samples(phy.rare, material == "Feces" & treatment == "VAN+PFOS") 

SUBS <- sample_names(phy.sub)

tmp.sub.dist <- tmp.dist[SUBS, SUBS]
jac.sub.dist <- as.dist(tmp.sub.dist,diag = TRUE, upper = TRUE)

# Calculate Jacrac distances

# Calculate PCoA data
jac.sub.pcoa <- ordinate(phy.sub, method = "PCoA",distance = jac.sub.dist)
jac.sub.nmds <- metaMDS(jac.sub.dist, k = 5, trymax = 1000)

# Save distance objects
save(phy.sub, jac.sub.dist, jac.sub.nmds, jac.sub.pcoa, file = "R_objects/jac.sub.feces_vanpfos.RData")

# clear the environment and release memory
rm(list = ls(all.names = TRUE))
invisible(gc())

2.3 BATCH EFFECTS

For the beta diversity we will also have to test for batch effects, and if they are significant, correct for them when performing the project relevant analyses. I will test each diversity index individually, so if additional indeces have been included, just copy and and adapt the following sections. Additional tests only including feces samples.

2.3.1 UNIFRAC

params <- readRDS("R_objects/bdiv_params.RDS")
# load
load("R_objects/Phyloseq_rarefied.Rdata")
load("R_objects/UniF.RData")

# Extract metadata from phyloseq
mdat <- data.frame(sample_data(phy.rare))

# Run PERMANOVA for batch variable
FORMULA <- as.formula(paste("unif.dist ~ ", params$batch, sep = ""))
batch.PERM <- adonis2(FORMULA, data = mdat)

# Compare the betadiversity dispertion for the batch variable
batch.bdisp <- betadisper(unif.dist, mdat[,params$batch])
anova(batch.bdisp)
## Analysis of Variance Table
## 
## Response: Distances
##            Df  Sum Sq  Mean Sq F value    Pr(>F)    
## Groups      2 0.45216 0.226081  45.562 < 2.2e-16 ***
## Residuals 264 1.30999 0.004962                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# If significant a post hoc test can compare pairwise
TukeyHSD(batch.bdisp)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##              diff         lwr         upr     p adj
## c3-c2 -0.04080482 -0.06602591 -0.01558373 0.0004996
## c4-c2 -0.10176916 -0.12723655 -0.07630176 0.0000000
## c4-c3 -0.06096434 -0.08518820 -0.03674048 0.0000000
plot(batch.bdisp)

boxplot(batch.bdisp)

# Subset for Feces
sub.phy <- subset_samples(phy.rare, material == "Feces")
mdat <- data.frame(sample_data(sub.phy))
load("R_objects/unif.sub.f0248.RData")

# Run PERMANOVA for batches only with Feces samples
FORMULA <- as.formula(paste("unif.sub.dist ~ ", params$batch, sep = ""))
batch.PERM <- adonis2(FORMULA, data = mdat)

# Compare the betadiversity dispertion for the batch variable
batch.bdisp <- betadisper(unif.sub.dist, mdat[,params$batch])
anova(batch.bdisp)
## Analysis of Variance Table
## 
## Response: Distances
##            Df  Sum Sq  Mean Sq F value    Pr(>F)    
## Groups      1 0.17465 0.174645  29.072 2.098e-07 ***
## Residuals 186 1.11736 0.006007                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# If significant a post hoc test can compare pairwise
TukeyHSD(batch.bdisp)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##              diff         lwr         upr p adj
## c4-c3 -0.06097162 -0.08328022 -0.03866303 2e-07
plot(batch.bdisp)

boxplot(batch.bdisp)

# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

Batch effect is observed between c2 and other two batches, as can be expected from difference in material origin (feces vs. cecum and ileum). Significant batch effect is observed between c3-c4 in unweighted UniFrac which should be taken into account in analysis between fecal samples over days d0/d8 to d2/d4. Due to the distribution of samples over batches, a difference is expected as the number of samples reflecting vancomycin treatment were different between the batches (higher portion of samples not exposed to vancomycin in c4).

2.3.2 WEIGHTED UNIFRAC

params <- readRDS("R_objects/bdiv_params.RDS")
# load
load(params$input)
load("R_objects/wuf.RData")

# Extract metadata from phyloseq
mdat <- data.frame(sample_data(phy))

# Run PERMANOVA for batch variable
FORMULA <- as.formula(paste("wuf.dist ~ ", params$batch, sep = ""))
batch.PERM <- adonis2(FORMULA, data = mdat)

# Compare the betadiversity dispertion for the batch variable
batch.bdisp <- betadisper(wuf.dist, mdat[,params$batch])
anova(batch.bdisp)
## Analysis of Variance Table
## 
## Response: Distances
##            Df Sum Sq Mean Sq F value    Pr(>F)    
## Groups      2 0.6925 0.34625  28.713 5.213e-12 ***
## Residuals 264 3.1836 0.01206                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# If significant a post hoc test can compare pairwise
TukeyHSD(batch.bdisp)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##               diff         lwr         upr     p adj
## c3-c2 -0.106616395 -0.14593436 -0.06729843 0.0000000
## c4-c2 -0.116062581 -0.15576453 -0.07636064 0.0000000
## c4-c3 -0.009446186 -0.04720954  0.02831717 0.8258281
plot(batch.bdisp)

boxplot(batch.bdisp)

# Subset for Feces
sub.phy <- subset_samples(phy, material == "Feces")
mdat <- data.frame(sample_data(sub.phy))
load("R_objects/wuf.sub.f0248.RData")

# Run PERMANOVA for batches only with Feces samples
FORMULA <- as.formula(paste("wuf.sub.dist ~ ", params$batch, sep = ""))
batch.PERM <- adonis2(FORMULA, data = mdat)

# Compare the betadiversity dispertion for the batch variable
batch.bdisp <- betadisper(wuf.sub.dist, mdat[,params$batch])
anova(batch.bdisp)
## Analysis of Variance Table
## 
## Response: Distances
##            Df Sum Sq   Mean Sq F value Pr(>F)
## Groups      1 0.0042 0.0041987  0.2996 0.5848
## Residuals 186 2.6067 0.0140143
# If significant a post hoc test can compare pairwise
TukeyHSD(batch.bdisp)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##               diff         lwr        upr     p adj
## c4-c3 -0.009453849 -0.04352746 0.02461976 0.5847871
plot(batch.bdisp)

boxplot(batch.bdisp)

# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

Batch effect is observed between c2 and other two batches, as can be expected from difference in material origin (feces vs. cecum and ileum). No batch effect is found between c3-c4 for weighted UniFrac.

2.3.3 BRAY-CURTIS

params <- readRDS("R_objects/bdiv_params.RDS")
# load
load(params$input)
load("R_objects/Bray.RData")

# Extract metadata from phyloseq
mdat <- data.frame(sample_data(phy))

# Run PERMANOVA for batch variable
FORMULA <- as.formula(paste("bray.dist ~ ", params$batch, sep = ""))
batch.PERM <- adonis2(FORMULA, data = mdat)

# Compare the betadiversity dispertion for the batch variable
batch.bdisp <- betadisper(bray.dist, mdat[,params$batch])
anova(batch.bdisp)
## Analysis of Variance Table
## 
## Response: Distances
##            Df  Sum Sq  Mean Sq F value    Pr(>F)    
## Groups      2 0.54409 0.272046  26.006 4.905e-11 ***
## Residuals 264 2.76163 0.010461                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# If significant a post hoc test can compare pairwise
TukeyHSD(batch.bdisp)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##              diff         lwr         upr     p adj
## c3-c2 -0.08392847 -0.12054791 -0.04730903 0.0000004
## c4-c2 -0.10897458 -0.14595164 -0.07199751 0.0000000
## c4-c3 -0.02504611 -0.06021764  0.01012543 0.2153761
plot(batch.bdisp)

boxplot(batch.bdisp)

# Subset for Feces
sub.phy <- subset_samples(phy, material == "Feces")
mdat <- data.frame(sample_data(sub.phy))
load("R_objects/bray.sub.f0248.RData")

# Run PERMANOVA for batches only with Feces samples
FORMULA <- as.formula(paste("bray.sub.dist ~ ", params$batch, sep = ""))
batch.PERM <- adonis2(FORMULA, data = mdat)

# Compare the betadiversity dispertion for the batch variable
batch.bdisp <- betadisper(bray.sub.dist, mdat[,params$batch])
anova(batch.bdisp)
## Analysis of Variance Table
## 
## Response: Distances
##            Df  Sum Sq  Mean Sq F value Pr(>F)
## Groups      1 0.02951 0.029508  2.3518 0.1268
## Residuals 186 2.33374 0.012547
# If significant a post hoc test can compare pairwise
TukeyHSD(batch.bdisp)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##              diff         lwr         upr     p adj
## c4-c3 -0.02506206 -0.05730258 0.007178457 0.1268396
plot(batch.bdisp)

boxplot(batch.bdisp)

# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

Batch effect is observed between c2 and other two batches, as can be expected from difference in material origin (feces vs. cecum and ileum). No batch effect is found between c3-c4 for Bray-Curtis.

2.3.4 JACCARD

params <- readRDS("R_objects/bdiv_params.RDS")
# load
load(params$input)
load("R_objects/jac.RData")

# Extract metadata from phyloseq
mdat <- data.frame(sample_data(phy))

# Run PERMANOVA for batch variable
FORMULA <- as.formula(paste("jac.dist ~ ", params$batch, sep = ""))
batch.PERM <- adonis2(FORMULA, data = mdat)

# Compare the betadiversity dispertion for the batch variable
batch.bdisp <- betadisper(jac.dist, mdat[,params$batch])
anova(batch.bdisp)
## Analysis of Variance Table
## 
## Response: Distances
##            Df  Sum Sq  Mean Sq F value   Pr(>F)    
## Groups      2 0.61309 0.306545  28.778 4.94e-12 ***
## Residuals 264 2.81211 0.010652                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# If significant a post hoc test can compare pairwise
TukeyHSD(batch.bdisp)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##              diff         lwr         upr     p adj
## c3-c2 -0.03918719 -0.07613985 -0.00223453 0.0347260
## c4-c2 -0.11670055 -0.15401409 -0.07938701 0.0000000
## c4-c3 -0.07751336 -0.11300493 -0.04202179 0.0000015
plot(batch.bdisp)

boxplot(batch.bdisp)

# Subset for Feces
sub.phy <- subset_samples(phy, material == "Feces")
mdat <- data.frame(sample_data(sub.phy))
load("R_objects/jac.sub.f0248.RData")

# Run PERMANOVA for batches only with Feces samples
FORMULA <- as.formula(paste("jac.sub.dist ~ ", params$batch, sep = ""))
batch.PERM <- adonis2(FORMULA, data = mdat)

# Compare the betadiversity dispertion for the batch variable
batch.bdisp <- betadisper(jac.sub.dist, mdat[,params$batch])
anova(batch.bdisp)
## Analysis of Variance Table
## 
## Response: Distances
##            Df  Sum Sq  Mean Sq F value    Pr(>F)    
## Groups      1 0.28226 0.282257  20.502 1.062e-05 ***
## Residuals 186 2.56071 0.013767                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# If significant a post hoc test can compare pairwise
TukeyHSD(batch.bdisp)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##              diff        lwr         upr    p adj
## c4-c3 -0.07751254 -0.1112845 -0.04374058 1.06e-05
plot(batch.bdisp)

boxplot(batch.bdisp)

# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

Batch effect is observed between c2 and other two batches, as can be expected from difference in material origin (feces vs. cecum and ileum). Significant batch effect is observed between c3-c4 in Jaccard which should be taken into account in analysis between fecal samples over days d0/d8 to d2/d4. Due to the distribution of samples over batches, a difference is expected as the number of samples reflecting vancomycin treatment were different between the batches (higher portion of samples not exposed to vancomycin in c4).

2.3.5 OVERALL INTERPRETATION

There were significant batch dependent differences in beta diversity in all investigated metrices, which need to be considered for further analysis. Due to sequencial run of samples batches the sample distribution for samples are not uniformly randomized on all three batches, rather the “c2” contains only samples from ileum and cecum luminal content, while “c3” and “c4” contains fecal samples of day 2-4 and day 0+8, respectively. This should be taken into account when comparing data between day 0 or 8 with day 2 or 4. Also, comparison with ileal and cecal samples should be weighted against this. Due to the distribution of samples over batches, a difference is expected as the number of samples reflecting vancomycin treatment were different between the batches c3 and c4 (higher portion of samples not exposed to vancomycin in c4).

3 GROUP-WISE TREATMENT - CATEGORICAL VARIABLES EFFECTS

In this first section (MANUAL) individual variables and metrices can be tested and plotted manually. In the second following section (PCOA ITERATIONS) all calculated iterations created during subsetting are analysed to create principal coordinate analyses through a for-loop created to select for appropriate variables and color-schemes for each iteration.

3.1 MANUAL

This first part loads the data and defines beta-diversity metric and tested variable for the following. Function ggExtra::ggMarginal is used for marginal boxplots for axis 1 and axis 2. OBS NMDS has been removed/silenced in the script below

params <- readRDS("R_objects/bdiv_params.RDS")

# Choose metric
METRIC <- "Bray"     # Metric for analysis: "Bray", "UniF", "WUF", "Jaccard"
# Choose variable 
VAR <- "treatment"   # Categorical factor - main
VAR2 <- "day"        # Categorical factor 2
DAY <- "d8"          # Values for "day": "d0", "d2", "d4", "d8"
MTRL <- "Feces"      # Materials: "Feces", "Cecum", "Ileum"
VAN <- "van"         # Variable for without and with vancomycin treatment: ctrl and van. Should be removed for test on all four treatment groups.
SUBNAME <- "f8_van"  # Subname should match the filename format for iterations used above: { METRIC.sub.SUBNAME.RData }
# Color scheme
COL <-  c("CTRL" = "#606060","PFOS" = "#31b44b","VAN" = "#6699d1","VAN+PFOS" = "#efc000")

# Create subfolder if needed
sub.dir <- paste0("plots/bdiv_manual/beta_",SUBNAME)
if (!file.exists(sub.dir)) dir.create(file.path(getwd(), sub.dir))
sdir <- paste0(sub.dir,"/")

# Load data based on METRIC
load(params$input)

if (METRIC == "UniF") {
  filename <- paste0("R_objects/unif.sub.",SUBNAME,".RData")
  load(filename)
  dist.used <- unif.sub.dist
  nmds.used <- unif.sub.nmds
  pcoa.used <- unif.sub.pcoa
  rm(unif.sub.dist, unif.sub.nmds, unif.sub.pcoa)
} else if (METRIC == "WUF") {
  filename <- paste0("R_objects/wuf.sub.",SUBNAME,".RData")
  load(filename)
  dist.used <- wuf.sub.dist
  nmds.used <- wuf.sub.nmds
  pcoa.used <- wuf.sub.pcoa
  rm(wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa)
} else if (METRIC == "Bray"){
  filename <- paste0("R_objects/bray.sub.",SUBNAME,".RData")
  load(filename)
  dist.used <- bray.sub.dist
  nmds.used <- bray.sub.nmds
  pcoa.used <- bray.sub.pcoa
  rm(bray.sub.dist, bray.sub.nmds, bray.sub.pcoa)
} else if (METRIC == "Jaccard"){
  filename <- paste0("R_objects/jac.sub.",SUBNAME,".RData")
  load(filename)
  dist.used <- jac.sub.dist
  nmds.used <- jac.sub.nmds
  pcoa.used <- jac.sub.pcoa
  rm(jac.sub.dist, jac.sub.nmds, jac.sub.pcoa)
}

# Extract metadata from phyloseq
mdat <- data.frame(sample_data(phy.sub))

# Subset the metadata based on the above
mdat <- mdat[mdat$day == DAY & mdat$material == MTRL,]

# If a variable consist of numbers, but represent distinct groups remember to make it into a factor
mdat[,VAR] <- as.factor(mdat[,VAR])

## STATISTICAL TEST
# Compare the betadiversity dispertion for Weighted UniFrac
bdisp <- betadisper(dist.used, mdat[,VAR], bias.adjust=TRUE)
test.anova <- anova(bdisp)
test.anova
## Analysis of Variance Table
## 
## Response: Distances
##           Df   Sum Sq   Mean Sq F value Pr(>F)
## Groups     1 0.012028 0.0120277  1.8373  0.192
## Residuals 18 0.117838 0.0065465
# dispertion by group
b.title <- paste0(METRIC," ",SUBNAME)
p.bdisp <- boxplot(bdisp, main = b.title)

# Test which groups differ (only if the anova test was significant)
(HSD <- TukeyHSD(bdisp))
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##                    diff         lwr       upr     p adj
## VAN+PFOS-VAN 0.04929339 -0.02711009 0.1256969 0.1920376
p.HSD <- plot(HSD)

# Run PERMANOVA for the variable
FORMULA <- as.formula(paste("dist.used ~", VAR, sep = " "))
(perm.test <- adonis2(FORMULA, data = mdat, permutations = 9999,na.action = na.omit))
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = FORMULA, data = mdat, permutations = 9999, na.action = na.omit)
##           Df SumOfSqs      R2      F Pr(>F)  
## treatment  1  0.19841 0.17732 3.8797 0.0124 *
## Residual  18  0.92052 0.82268                
## Total     19  1.11893 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
FORMULA2 <- as.formula(paste("dist.used ~", "pfos", sep = " "))
(perm.test2 <- adonis2(FORMULA2, data = mdat, permutations = 9999,na.action = na.omit))
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = FORMULA2, data = mdat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## pfos      1  0.19841 0.17732 3.8797 0.0124 *
## Residual 18  0.92052 0.82268                
## Total    19  1.11893 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Use vegan to test how well metadata fits ordination
fit.out <- envfit(nmds.used, mdat[,c(VAR,VAR2)],na.rm=TRUE)
fit.out
## 
## ***FACTORS:
## 
## Centroids:
##                     NMDS1   NMDS2
## treatmentVAN      -0.0875  0.0648
## treatmentVAN+PFOS  0.0716 -0.0531
## dayd8              0.0000  0.0000
## 
## Goodness of fit:
##               r2 Pr(>r)  
## treatment 0.2402  0.012 *
## day       0.0000  1.000  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Permutation: free
## Number of permutations: 999
# ### EIGENVALUES
# For PCoA each axis represent a specific amount of the overall variation in the dataset. this information can easily be extracted and plotted.

# Extract eigen values
eigen <- pcoa.used$values
eigen$Axis <- as.numeric(row.names(eigen))

# Create plots for both distance indeces
p.eigen <- ggplot(eigen[1:10,], aes(x = as.factor(Axis), y = 100*Rel_corr_eig)) + 
  geom_col(aes(fill = as.factor(Axis))) +
  geom_point(aes(x = Axis, y = 100*Cum_corr_eig)) +
  geom_line(aes(x = Axis, y = 100*Cum_corr_eig)) +
  ylab("Variance explained (%)") +
  xlab("Axis") +
  theme_pubr(legend = "none") + ggsci::scale_fill_jco()
p.eigen + ggtitle(paste("Variance per axis for", METRIC, sep = " "))

suppressMessages(ggsave(plot = p.eigen, filename = paste0(sdir,"bdiv_eigen_",METRIC,"_",SUBNAME,".png"), device = "png"))
suppressMessages(ggsave(plot = p.eigen, filename = paste0(sdir,"bdiv_eigen_",METRIC,"_",SUBNAME,".pdf"), device = "pdf"))

### ORDINATION

# Phyloseq has a plotting function, but it is a bit limited in some of the settings. Therefore, I recommend to use the function to create a table of the data and then make your own plots
# The first plot highlights the location of each group on the first 5 axis. Based on this an optimal set of axis can be chosen for the following ordination plot.

# Create plots of eigenvalues for PCoA plots
pcoa.tab <- plot_ordination(phy, pcoa.used,axes = 1:5,justDF = TRUE)
nmds.tab <- plot_ordination(phy, nmds.used,axes = 1:5,justDF = TRUE)

# Reformat tables to create one common table
colnames(nmds.tab)[1:5] <- c("Axis.1","Axis.2","Axis.3","Axis.4","Axis.5")

nmds.tab$ordination <- "nmds"
pcoa.tab$ordination <- "pcoa"

ord.tab <- rbind(nmds.tab,pcoa.tab)
ord.tab$treatment <- as.factor(ord.tab$treatment)

# Melt axis to be in one variable
axis.tab <- pivot_longer(data = ord.tab, cols = c("Axis.1","Axis.2","Axis.3","Axis.4","Axis.5"), names_to = "Axis", values_to = "position")

# Plot positions on axes
plot.pos <- ggplot(axis.tab, aes_string(x = "ordination", y = "position", fill = VAR)) +
  geom_boxplot() +
  facet_grid(Axis~.) +
  coord_flip() + 
  theme_pubr(legend = "bottom") + ggsci::scale_fill_jco()
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation ideoms with `aes()`
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
TITLE <- paste0(METRIC," - Axis effect: ",MTRL," ","day ",DAY)
plot.pos2 <- print(plot.pos + ggtitle(TITLE))

plot.pos2
suppressMessages(ggsave(plot = plot.pos2, filename = paste0(sdir,"bdiv_axis_effect_",METRIC,"_",SUBNAME,".png"), device = "png"))
suppressMessages(ggsave(plot = plot.pos2, filename = paste0(sdir,"bdiv_axis_effect_",METRIC,"_",SUBNAME,".pdf"), device = "pdf"))

# Create PCoA plot
p <- ggplot(ord.tab[ord.tab$ordination == "pcoa",], aes_string(x = "Axis.1", y = "Axis.2", color = VAR, fill = VAR, group = VAR))
p <- p + geom_vline(xintercept = c(0), color = "grey70", alpha = 0.6, linetype = 1, linewidth = 0.5) +
  geom_hline(yintercept = c(0), color = "grey70", alpha = 0.6, linetype = 1, linewidth = 0.5) +
  geom_point() +
  theme_pubr(legend = "bottom") +
  labs(color=VAR) +
  stat_ellipse(geom = "polygon", alpha = 0.1) +
  scale_color_manual(values = COL) +
  scale_fill_manual(values = COL) +
  border(color = "black",size = 0.5) +
  labs(color = "Treatment") +
  guides(fill = "none")
p.pcoa <- ggExtra::ggMarginal(p = p, type = 'boxplot', size = 10, groupFill = TRUE)
p.pcoa

# Save plot
plotfile <- file.path("plots/bdiv",paste0("bdiv_ordination_",VAR,".png"))
ggsave(filename = plotfile, plot = p.pcoa, width = 150, height = 150, device = "png", units = "mm",dpi = 300)
# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

3.2 ALL PCOA ITERATIONS

For-loop setup to generate analysis and PCoA visualization for all listed iterations. Eigenvalue plot is excluded from the loop due to constant errors related to calculations of “Rel_corr_eig”. Function ggExtra::ggMarginal is used for marginal boxplots for axis 1 and axis 2. OBS NMDS has been removed/silenced in the script below

params <- readRDS("R_objects/bdiv_params.RDS")
# Default variables
VAR <- "treatment"
VAR2 <- "day"
# Default color scheme for treatment groups 
COL <-  c("CTRL" = "#606060","PFOS" = "#31b44b","VAN" = "#6699d1","VAN+PFOS" = "#efc000")

# Create string of iterations based on subsets created above = SUBNAME
str.subnameT<- c("feces_ctrl","feces_pfos","feces_van","feces_vanpfos",
                 "f0","f0_ctrl","f0_van","f2","f2_ctrl","f2_van",
                 "f4","f4_ctrl","f4_van",
                 "f8","f8_ctrl","f8_van",
                 "il8","il8_ctrl","il8_van",
                 "ce8","ce8_ctrl","ce8_van",
                 "f08","f0248")

# Determine variables for sub-setting and naming the run
for (SUBNAME in str.subnameT) {
  VAR <- "treatment"
  VAR2 <- "day"
  COL <-  c("CTRL" = "#606060","PFOS" = "#31b44b","VAN" = "#6699d1","VAN+PFOS" = "#efc000")
  print(paste0("Processing ",SUBNAME,"..."))
  if (grepl("feces_",SUBNAME) == TRUE) {
    MTRL <- "Feces"
    MN <- MTRL
    VAR <- "day"
    VAR2 <- "treatment"
    DAY <- c("d0","d2","d4","d8")
    dn <- "All days"
  } else if (grepl("fceil",SUBNAME) == TRUE) {
    MTRL <- c("Feces","Cecum","Ileum")
    MN <- "All materials"
    VAR <- "material"
    VAR2 <- "treatment"
    COL <- c("Feces" = "#cd534c","Cecum" = "#efc000","Ileum" = "#0073c2")
  } else if (grepl("f",SUBNAME) == TRUE) {
    MTRL <- "Feces"
    MN <- MTRL
  } else if (grepl("ce",SUBNAME) == TRUE) {
    MTRL <- "Cecum"
    MN <- MTRL
  } else if (grepl("il",SUBNAME) == TRUE) {
    MTRL <- "Ileum"
    MN <- MTRL
  }
  if (grepl("feces_",SUBNAME) == TRUE) {
    if (grepl("_ctrl",SUBNAME) == TRUE) {
      COL <- c("d0" = "#a0a0a0","d2" = "#808080","d4" = "#606060","d8" = "#494949")
      print("Treatment sorting. No vancomycin definition needed")
    } else if (grepl("_pfos",SUBNAME) == TRUE) {
      COL <- c("d0" = "#48ff62","d2" = "#45ce4b","d4" = "#31b44b","d8" = "#278937")
      print("Treatment sorting. No vancomycin definition needed")
    } else if (grepl("_vanpfos",SUBNAME) == TRUE) {
      COL <- c("d0" = "#f7e789","d2" = "#f7e054","d4" = "#fcdd05","d8" = "#c4a110")
      print("Treatment sorting. No vancomycin definition needed")
    } else if (grepl("_van",SUBNAME) == TRUE) {
      COL <- c("d0" = "#8bd2fc","d2" = "#81c3ea","d4" = "#6699d1","d8" = "#487baa")
      print("Treatment sorting. No vancomycin definition needed")
    }
  } else if (grepl("ctrl", SUBNAME) == TRUE) {
    STA <- "ctrl"
  } else if (grepl("van", SUBNAME) == TRUE) {
    STA <- "van"
  } else {
  }
  if (grepl("0248",SUBNAME) == TRUE) {
    DAY <- c("d0","d2","d4","d8")
    dn <- "All days"
  } else if (grepl("08",SUBNAME) == TRUE) {
    DAY <- c("d0","d8")
    dn <- "Day 0 + 8"
  } else if (grepl("0", SUBNAME) == TRUE) {
    DAY <- "d0"
    dn <- "Day 0"
  } else if (grepl("2", SUBNAME) == TRUE) {
    DAY <- "d2"
    dn <- "Day 2"
  } else if (grepl("4", SUBNAME) == TRUE) {
    DAY <- "d4"
    dn <- "Day 4"
  } else if (grepl("8", SUBNAME) == TRUE) {
    DAY <- "d8"
    dn <- "Day 8"
  }

  sub.dir <- paste0("plots/bdiv/beta_",SUBNAME)
  if (!file.exists(sub.dir)) dir.create(file.path(getwd(), sub.dir))
  sdir <- paste0(sub.dir,"/")

  for (METRIC in params$metrices) {
  # Load data
    print(paste0("Processing ",SUBNAME," in ",METRIC,"..."))
    load(params$input)
    #METRIC <- "UniF"
    if (METRIC == "UniF") {
      filename <- paste0("R_objects/unif.sub.",SUBNAME,".RData")
      load(filename)
      dist.used <- unif.sub.dist
      nmds.used <- unif.sub.nmds
      pcoa.used <- unif.sub.pcoa
      rm(unif.sub.dist, unif.sub.nmds, unif.sub.pcoa)
    } else if (METRIC == "WUF") {
      filename <- paste0("R_objects/wuf.sub.",SUBNAME,".RData")
      load(filename)
      dist.used <- wuf.sub.dist
      nmds.used <- wuf.sub.nmds
      pcoa.used <- wuf.sub.pcoa
      rm(wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa)
    } else if (METRIC == "Bray"){
      filename <- paste0("R_objects/bray.sub.",SUBNAME,".RData")
      load(filename)
      dist.used <- bray.sub.dist
      nmds.used <- bray.sub.nmds
      pcoa.used <- bray.sub.pcoa
      rm(bray.sub.dist, bray.sub.nmds, bray.sub.pcoa)
    } else if (METRIC == "Jaccard"){
      filename <- paste0("R_objects/jac.sub.",SUBNAME,".RData")
      load(filename)
      dist.used <- jac.sub.dist
      nmds.used <- jac.sub.nmds
      pcoa.used <- jac.sub.pcoa
      rm(jac.sub.dist, jac.sub.nmds, jac.sub.pcoa)
    }
    
    # Extract metadata from phyloseq
    mdat <- data.frame(sample_data(phy.sub))
    
    # Subset the metadata based on the above
    if (grepl("feces_",SUBNAME) == TRUE) {
      mdat <- mdat[mdat$day %in% DAY & mdat$material %in% MTRL,]
    } else if (grepl("_",SUBNAME) == FALSE) {
      mdat <- mdat[mdat$day %in% DAY & mdat$material %in% MTRL,]
    } else {
      mdat <- mdat[mdat$day %in% DAY & mdat$material %in% MTRL & mdat$van %in% STA,]
    }
    
    # If a variable consist of numbers, but represent distinct groups remember to make it into a factor
    mdat[,VAR] <- as.factor(mdat[,VAR])
    
    ## STATISTICAL TEST
    # Compare the betadiversity dispertion for Weighted UniFrac
    bdisp <- betadisper(dist.used, mdat[,VAR], bias.adjust=TRUE)
    test.anova <- anova(bdisp)
    test.anova
    
    # dispertion by group
    b.title <- paste0(METRIC," ",SUBNAME)
    p.bdisp <- boxplot(bdisp, main = b.title)
    
    png(file = paste0(sdir,"bdiv_bdisp_boxplot_",METRIC,"_",SUBNAME,".png"))
    boxplot(bdisp, main = b.title)
    dev.off()
    
    # Test which groups differ (only if the anova test was significant)
    (HSD <- TukeyHSD(bdisp))
    p.HSD <- plot(HSD)
    
    png(file = paste0(sdir,"bdiv_bdisp_HSD_",METRIC,"_",SUBNAME,".png"))
    plot(HSD)
    dev.off()
    
    # Run PERMANOVA for the variable
    FORMULA <- as.formula(paste("dist.used ~", VAR, sep = " "))
    (perm.test <- adonis2(FORMULA, data = mdat, permutations = 9999,na.action = na.omit))
    
    # Use vegan to test how well metadata fits ordination
    fit.out <- envfit(nmds.used, mdat[,c(VAR,VAR2)],na.rm=TRUE)
    fit.out
    
    stat.out <- paste0(sdir,"bdiv_bdisp_",METRIC,"_",SUBNAME,".txt")
    sink(stat.out)
    print(test.anova)
    print(perm.test)
    print(fit.out)
    sink()
    
    ### ORDINATION
    # Create plots of eigenvalues for PCoA plots
    pcoa.tab <- plot_ordination(phy, pcoa.used,axes = 1:5,justDF = TRUE)
    #nmds.tab <- plot_ordination(phy, nmds.used,axes = 1:5,justDF = TRUE)
    
    # Reformat tables to create one common table
    #colnames(nmds.tab)[1:5] <- c("Axis.1","Axis.2","Axis.3","Axis.4","Axis.5")
    
    #nmds.tab$ordination <- "nmds"
    pcoa.tab$ordination <- "pcoa"
    
    ord.tab <- rbind(pcoa.tab) #nmds.tab,
    ord.tab$treatment <- as.factor(ord.tab$treatment)
    
    # Melt axis to be in one variable
    axis.tab <- pivot_longer(data = ord.tab, cols = c("Axis.1","Axis.2","Axis.3","Axis.4","Axis.5"), names_to = "Axis", values_to = "position")
    
    # Plot positions on axes
    plot.pos <- ggplot(axis.tab, aes_string(x = "ordination", y = "position", fill = VAR)) +
      geom_boxplot() +
      facet_grid(Axis~.) +
      coord_flip() + 
      theme_pubr(legend = "bottom") + scale_fill_manual(values = COL)#ggsci::scale_fill_jco()
    plot.posT <- plot.pos + ggtitle(paste0(METRIC," - Axis effect: ",MN," ",dn))
    suppressMessages(ggsave(plot = plot.posT, filename = paste0(sdir,"bdiv_axis_effect_",METRIC,"_",SUBNAME,".png"), device = "png", units = "mm", width = 200, height = 100, dpi = 300))
    suppressMessages(ggsave(plot = plot.posT, filename = paste0(sdir,"bdiv_axis_effect_",METRIC,"_",SUBNAME,".pdf"), device = "pdf", units = "mm", width = 200, height = 100, dpi = 300))
    
    # Create ordination plots
    p <- ggplot(ord.tab[ord.tab$ordination == "pcoa",], aes_string(x = "Axis.1", y = "Axis.2", color = VAR, fill = VAR, group = VAR))
    p <- p + 
      #geom_vline(xintercept = c(0), color = "grey70", alpha = 0.4, linetype = 1, linewidth = 0.5) +
      #geom_hline(yintercept = c(0), color = "grey70", alpha = 0.4, linetype = 1, linewidth = 0.5) +
      geom_point() +
      theme_pubr(legend = "bottom") +
      labs(color=VAR) +
      stat_ellipse(geom = "polygon", alpha = 0.1) +
      scale_color_manual(values = COL) +
      scale_fill_manual(values = COL) +
      border(color = "black",size = 0.5) +
      labs(color = "Treatment") +
      guides(fill = "none")
    plot.beta <- ggExtra::ggMarginal(p = p, type = 'boxplot', size = 10, groupFill = TRUE)
      
    suppressMessages(ggsave(filename = paste0(sdir,"bdiv_PCoA_",METRIC,"_",SUBNAME,".png"), plot.beta, device = "png", units = "mm", width = 150, height = 150, dpi = 300))
    suppressMessages(ggsave(filename = paste0(sdir,"bdiv_PCoA_",METRIC,"_",SUBNAME,".pdf"), plot.beta, device = "pdf", units = "mm", width = 150, height = 150, dpi = 300))

  message(paste0("Finished processing ",SUBNAME," without issues. Moving on..."))
  } 
  # clear the environment and release memory except variables used for next run
  rm(list = ls(all.names = TRUE)[!ls(all.names = TRUE) %in% c("params","VAR","VAR2","str.subnameT","COL")])
  invisible(gc())
}
## [1] "Processing feces_ctrl..."
## [1] "Treatment sorting. No vancomycin definition needed"
## [1] "Processing feces_ctrl in UniF..."

## Finished processing feces_ctrl without issues. Moving on...

## [1] "Processing feces_ctrl in Bray..."

## Finished processing feces_ctrl without issues. Moving on...

## [1] "Processing feces_pfos..."
## [1] "Treatment sorting. No vancomycin definition needed"
## [1] "Processing feces_pfos in UniF..."

## Finished processing feces_pfos without issues. Moving on...

## [1] "Processing feces_pfos in Bray..."

## Finished processing feces_pfos without issues. Moving on...

## [1] "Processing feces_van..."
## [1] "Treatment sorting. No vancomycin definition needed"
## [1] "Processing feces_van in UniF..."

## Finished processing feces_van without issues. Moving on...
## [1] "Processing feces_van in Bray..."
## Warning in betadisper(dist.used, mdat[, VAR], bias.adjust = TRUE): some squared
## distances are negative and changed to zero

## Finished processing feces_van without issues. Moving on...

## [1] "Processing feces_vanpfos..."
## [1] "Treatment sorting. No vancomycin definition needed"
## [1] "Processing feces_vanpfos in UniF..."

## Finished processing feces_vanpfos without issues. Moving on...

## [1] "Processing feces_vanpfos in Bray..."

## Finished processing feces_vanpfos without issues. Moving on...

## [1] "Processing f0..."
## [1] "Processing f0 in UniF..."

## Finished processing f0 without issues. Moving on...

## [1] "Processing f0 in Bray..."

## Finished processing f0 without issues. Moving on...

## [1] "Processing f0_ctrl..."
## [1] "Processing f0_ctrl in UniF..."

## Finished processing f0_ctrl without issues. Moving on...

## [1] "Processing f0_ctrl in Bray..."

## Finished processing f0_ctrl without issues. Moving on...

## [1] "Processing f0_van..."
## [1] "Processing f0_van in UniF..."

## Finished processing f0_van without issues. Moving on...

## [1] "Processing f0_van in Bray..."

## Finished processing f0_van without issues. Moving on...

## [1] "Processing f2..."
## [1] "Processing f2 in UniF..."

## Finished processing f2 without issues. Moving on...
## [1] "Processing f2 in Bray..."
## Warning in betadisper(dist.used, mdat[, VAR], bias.adjust = TRUE): some squared
## distances are negative and changed to zero

## Finished processing f2 without issues. Moving on...

## [1] "Processing f2_ctrl..."
## [1] "Processing f2_ctrl in UniF..."

## Finished processing f2_ctrl without issues. Moving on...

## [1] "Processing f2_ctrl in Bray..."

## Finished processing f2_ctrl without issues. Moving on...

## [1] "Processing f2_van..."
## [1] "Processing f2_van in UniF..."

## Finished processing f2_van without issues. Moving on...

## [1] "Processing f2_van in Bray..."

## Finished processing f2_van without issues. Moving on...

## [1] "Processing f4..."
## [1] "Processing f4 in UniF..."

## Finished processing f4 without issues. Moving on...

## [1] "Processing f4 in Bray..."

## Finished processing f4 without issues. Moving on...

## [1] "Processing f4_ctrl..."
## [1] "Processing f4_ctrl in UniF..."

## Finished processing f4_ctrl without issues. Moving on...

## [1] "Processing f4_ctrl in Bray..."

## Finished processing f4_ctrl without issues. Moving on...

## [1] "Processing f4_van..."
## [1] "Processing f4_van in UniF..."

## Finished processing f4_van without issues. Moving on...

## [1] "Processing f4_van in Bray..."

## Finished processing f4_van without issues. Moving on...

## [1] "Processing f8..."
## [1] "Processing f8 in UniF..."

## Finished processing f8 without issues. Moving on...

## [1] "Processing f8 in Bray..."

## Finished processing f8 without issues. Moving on...

## [1] "Processing f8_ctrl..."
## [1] "Processing f8_ctrl in UniF..."

## Finished processing f8_ctrl without issues. Moving on...

## [1] "Processing f8_ctrl in Bray..."

## Finished processing f8_ctrl without issues. Moving on...

## [1] "Processing f8_van..."
## [1] "Processing f8_van in UniF..."

## Finished processing f8_van without issues. Moving on...

## [1] "Processing f8_van in Bray..."

## Finished processing f8_van without issues. Moving on...

## [1] "Processing il8..."
## [1] "Processing il8 in UniF..."

## Finished processing il8 without issues. Moving on...

## [1] "Processing il8 in Bray..."

## Finished processing il8 without issues. Moving on...

## [1] "Processing il8_ctrl..."
## [1] "Processing il8_ctrl in UniF..."

## Finished processing il8_ctrl without issues. Moving on...

## [1] "Processing il8_ctrl in Bray..."

## Finished processing il8_ctrl without issues. Moving on...

## [1] "Processing il8_van..."
## [1] "Processing il8_van in UniF..."

## Finished processing il8_van without issues. Moving on...

## [1] "Processing il8_van in Bray..."

## Finished processing il8_van without issues. Moving on...

## [1] "Processing ce8..."
## [1] "Processing ce8 in UniF..."

## Finished processing ce8 without issues. Moving on...

## [1] "Processing ce8 in Bray..."

## Finished processing ce8 without issues. Moving on...

## [1] "Processing ce8_ctrl..."
## [1] "Processing ce8_ctrl in UniF..."

## Finished processing ce8_ctrl without issues. Moving on...

## [1] "Processing ce8_ctrl in Bray..."

## Finished processing ce8_ctrl without issues. Moving on...

## [1] "Processing ce8_van..."
## [1] "Processing ce8_van in UniF..."

## Finished processing ce8_van without issues. Moving on...

## [1] "Processing ce8_van in Bray..."

## Warning in MASS::cov.trob(data[, vars]): Probable convergence failure
## Warning in MASS::cov.trob(data[, vars]): Probable convergence failure
## Finished processing ce8_van without issues. Moving on...

## [1] "Processing f08..."
## [1] "Processing f08 in UniF..."

## Finished processing f08 without issues. Moving on...

## [1] "Processing f08 in Bray..."

## Finished processing f08 without issues. Moving on...

## [1] "Processing f0248..."
## [1] "Processing f0248 in UniF..."

## Finished processing f0248 without issues. Moving on...

## [1] "Processing f0248 in Bray..."

## Finished processing f0248 without issues. Moving on...

# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4 PERMANOVA

In this section the contribution of categorical values for treatment (“pfos” and “van” = vancomycin) to beta diversity distances for each metric is tested using PERMANOVA test (vegan::adonis2). Tests for each sampling day are tested and for subsets based on vancomycin treatment.

4.1 PERMANOVA FECES DAY 0

MTRL <- "Feces"
DAY <- "Day 0"

# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.f0"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d0",]
perm.unif <- adonis2(unif.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on UniF: Feces Day 0
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## van       1  0.05458 0.02071 0.9681 0.4785
## pfos      1  0.04814 0.01827 0.8538 0.6789
## van:pfos  1  0.05179 0.01965 0.9186 0.5661
## Residual 44  2.48074 0.94137              
## Total    47  2.63526 1.00000
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.f0"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d0",]
perm.wuf <- adonis2(wuf.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on WUF: Feces Day 0
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## van       1   0.1348 0.03817 1.8351 0.1171
## pfos      1   0.1003 0.02841 1.3661 0.2327
## van:pfos  1   0.0647 0.01833 0.8813 0.4625
## Residual 44   3.2319 0.91509              
## Total    47   3.5318 1.00000
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.f0"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d0",]
perm.bray <- adonis2(bray.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Bray: Feces Day 0
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)   
## van       1   0.3785 0.05213 2.6575 0.0157 * 
## pfos      1   0.1851 0.02549 1.2994 0.2272   
## van:pfos  1   0.4304 0.05927 3.0216 0.0068 **
## Residual 44   6.2669 0.86311                 
## Total    47   7.2608 1.00000                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.f0"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d0",]
perm.jac <- adonis2(jac.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Jaccard: Feces Day 0
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## van       1   0.1442 0.03298 1.5828 0.0177 *
## pfos      1   0.1171 0.02678 1.2851 0.0954 .
## van:pfos  1   0.1027 0.02348 1.1270 0.2296  
## Residual 44   4.0083 0.91676                
## Total    47   4.3723 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4.2 PERMANOVA FECES DAY 2

MTRL <- "Feces"
DAY <- "Day 2"

# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.f2"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2",]
perm.unif <- adonis2(unif.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on UniF: Feces Day 2
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   2.0758 0.38711 28.9219 0.0001 ***
## pfos      1   0.0542 0.01010  0.7548 0.5668    
## van:pfos  1   0.0744 0.01387  1.0365 0.3192    
## Residual 44   3.1580 0.58892                   
## Total    47   5.3623 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.f2"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2",]
perm.wuf <- adonis2(wuf.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on WUF: Feces Day 2
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs       R2       F Pr(>F)    
## van       1   2.9042  0.47832 43.8835 0.0001 ***
## pfos      1  -0.0172 -0.00283 -0.2599 1.0000    
## van:pfos  1   0.2727  0.04492  4.1208 0.0172 *  
## Residual 44   2.9120  0.47959                   
## Total    47   6.0717  1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.f2"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2",]
perm.bray <- adonis2(bray.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Bray: Feces Day 2
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   5.6191 0.50024 47.1487 0.0001 ***
## pfos      1   0.0233 0.00207  0.1951 0.9826    
## van:pfos  1   0.3467 0.03086  2.9091 0.0357 *  
## Residual 44   5.2438 0.46683                   
## Total    47  11.2329 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.f2"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2",]
perm.jac <- adonis2(jac.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Jaccard: Feces Day 2
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   2.9793 0.31069 20.7050 0.0001 ***
## pfos      1   0.1409 0.01469  0.9790 0.3502    
## van:pfos  1   0.1378 0.01437  0.9578 0.3658    
## Residual 44   6.3312 0.66025                   
## Total    47   9.5892 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
as.data.frame(perm.unif)["pfos","Pr(>F)"]
## [1] 0.5668
coef <- coefficients(perm.unif)["",]


# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4.3 PERMANOVA FECES day 2 CTRL & VAN

MTRL <- "Feces"
DAY <- "Day 2"
VAN <- "no vancomycin"

# No vancomycin treatment
message(paste0("PERMANOVA distance test for PFOS effect on ",MTRL," ",DAY," with ",VAN))
## PERMANOVA distance test for PFOS effect on Feces Day 2 with no vancomycin
# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.f2_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2" & dat$van == "ctrl",]
perm.unif <- adonis2(unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on UniF: Feces Day 2 no vancomycin
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.05452 0.03947 0.9041 0.5951
## Residual 22  1.32675 0.96053              
## Total    23  1.38128 1.00000
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.f2_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2" & dat$van == "ctrl",]
perm.wuf <- adonis2(wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on WUF: Feces Day 2 no vancomycin
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.08823 0.03853 0.8816   0.44
## Residual 22  2.20183 0.96147              
## Total    23  2.29007 1.00000
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.f2_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2" & dat$van == "ctrl",]
perm.bray <- adonis2(bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Bray: Feces Day 2 no vancomycin
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1   0.1811 0.04487 1.0335   0.39
## Residual 22   3.8546 0.95513              
## Total    23   4.0357 1.00000
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.f2_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2" & dat$van == "ctrl",]
perm.jac <- adonis2(jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Jaccard: Feces Day 2 no vancomycin
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.09823 0.04208 0.9663  0.525
## Residual 22  2.23634 0.95792              
## Total    23  2.33457 1.00000
message("")
## 
# With vancomycin treatment
VAN <- "vancomycin"
message(paste0("PERMANOVA distance test for PFOS effect on ",MTRL," ",DAY," with ",VAN))
## PERMANOVA distance test for PFOS effect on Feces Day 2 with vancomycin
# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.f2_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2" & dat$van == "van",]
perm.unif <- adonis2(unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on UniF: Feces Day 2 vancomycin
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.07404 0.03886 0.8895 0.6199
## Residual 22  1.83121 0.96114              
## Total    23  1.90526 1.00000
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.f2_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2" & dat$van == "van",]
perm.wuf <- adonis2(wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on WUF: Feces Day 2 vancomycin
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)   
## pfos      1  0.16728 0.19066 5.1826 0.0024 **
## Residual 22  0.71012 0.80934                 
## Total    23  0.87740 1.00000                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.f2_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2" & dat$van == "van",]
perm.bray <- adonis2(bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Bray: Feces Day 2 vancomycin
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## pfos      1  0.18888 0.11969 2.9911 0.0376 *
## Residual 22  1.38920 0.88031                
## Total    23  1.57807 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.f2_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d2" & dat$van == "van",]
perm.jac <- adonis2(jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Jaccard: Feces Day 2 vancomycin
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1   0.1805 0.04221 0.9695 0.5209
## Residual 22   4.0949 0.95779              
## Total    23   4.2753 1.00000
# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4.4 PERMANOVA FECES DAY 4

MTRL <- "Feces"
DAY <- "Day 4"

# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.f4"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4",]
perm.unif <- adonis2(unif.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on UniF: Feces Day 4
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   3.2083 0.53002 52.0757 0.0001 ***
## pfos      1   0.0638 0.01054  1.0356 0.3001    
## van:pfos  1   0.0703 0.01162  1.1417 0.2632    
## Residual 44   2.7108 0.44782                   
## Total    47   6.0532 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.f4"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4",]
perm.wuf <- adonis2(wuf.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on WUF: Feces Day 4
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   3.8035 0.53562 52.2357 0.0001 ***
## pfos      1   0.0345 0.00485  0.4731 0.6680    
## van:pfos  1   0.0593 0.00835  0.8142 0.4297    
## Residual 44   3.2038 0.45118                   
## Total    47   7.1011 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.f4"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4",]
perm.bray <- adonis2(bray.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Bray: Feces Day 4
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   6.3102 0.52877 52.7557 0.0001 ***
## pfos      1   0.1832 0.01535  1.5319 0.1831    
## van:pfos  1   0.1773 0.01486  1.4825 0.1909    
## Residual 44   5.2629 0.44101                   
## Total    47  11.9337 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.f4"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4",]
perm.jac <- adonis2(jac.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Jaccard: Feces Day 4
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   4.7484 0.44485 37.5221 0.0001 ***
## pfos      1   0.1839 0.01723  1.4531 0.1642    
## van:pfos  1   0.1737 0.01627  1.3724 0.1930    
## Residual 44   5.5682 0.52165                   
## Total    47  10.6742 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
as.data.frame(perm.unif)["pfos","Pr(>F)"]
## [1] 0.3001
coef <- coefficients(perm.unif)["",]


# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4.5 PERMANOVA FECES day 4 CTRL & VAN

MTRL <- "Feces"
DAY <- "Day 4"
VAN <- "no vancomycin"

# No vancomycin treatment
message(paste0("PERMANOVA distance test for PFOS effect on ",MTRL," ",DAY," with ",VAN))
## PERMANOVA distance test for PFOS effect on Feces Day 4 with no vancomycin
# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.f4_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4" & dat$van == "ctrl",]
perm.unif <- adonis2(unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on UniF: Feces Day 4 no vancomycin
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.06007 0.04471 1.0296 0.4106
## Residual 22  1.28355 0.95529              
## Total    23  1.34362 1.00000
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.f4_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4" & dat$van == "ctrl",]
perm.wuf <- adonis2(wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on WUF: Feces Day 4 no vancomycin
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.03386 0.01423 0.3176 0.8328
## Residual 22  2.34531 0.98577              
## Total    23  2.37917 1.00000
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.f4_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4" & dat$van == "ctrl",]
perm.bray <- adonis2(bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Bray: Feces Day 4 no vancomycin
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1   0.1431 0.03436 0.7829 0.5329
## Residual 22   4.0204 0.96564              
## Total    23   4.1635 1.00000
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.f4_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4" & dat$van == "ctrl",]
perm.jac <- adonis2(jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Jaccard: Feces Day 4 no vancomycin
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.10849 0.04725 1.0911 0.3002
## Residual 22  2.18769 0.95275              
## Total    23  2.29619 1.00000
message("")
## 
# With vancomycin treatment
VAN <- "vancomycin"
message(paste0("PERMANOVA distance test for PFOS effect on ",MTRL," ",DAY," with ",VAN))
## PERMANOVA distance test for PFOS effect on Feces Day 4 with vancomycin
# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.f4_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4" & dat$van == "van",]
perm.unif <- adonis2(unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on UniF: Feces Day 4 vancomycin
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.07407 0.04934 1.1417 0.2939
## Residual 22  1.42721 0.95066              
## Total    23  1.50128 1.00000
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.f4_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4" & dat$van == "van",]
perm.wuf <- adonis2(wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on WUF: Feces Day 4 vancomycin
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs     R2      F Pr(>F)
## pfos      1  0.05988 0.0652 1.5344 0.2005
## Residual 22  0.85853 0.9348              
## Total    23  0.91841 1.0000
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.f4_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4" & dat$van == "van",]
perm.bray <- adonis2(bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Bray: Feces Day 4 vancomycin
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2     F Pr(>F)  
## pfos      1  0.21749 0.14897 3.851 0.0243 *
## Residual 22  1.24248 0.85103               
## Total    23  1.45997 1.00000               
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.f4_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d4" & dat$van == "van",]
perm.jac <- adonis2(jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Jaccard: Feces Day 4 vancomycin
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2     F Pr(>F)   
## pfos      1   0.2491 0.06862 1.621 0.0099 **
## Residual 22   3.3805 0.93138                
## Total    23   3.6296 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4.6 PERMANOVA FECES DAY 8

MTRL <- "Feces"
DAY <- "Day 8"

# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.f8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8",]
perm.unif <- adonis2(unif.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on UniF: Feces Day 8
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   2.4691 0.54875 53.0629 0.0001 ***
## pfos      1   0.0949 0.02110  2.0404 0.0902 .  
## van:pfos  1   0.0742 0.01650  1.5951 0.1580    
## Residual 40   1.8613 0.41366                   
## Total    43   4.4996 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.f8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8",]
perm.wuf <- adonis2(wuf.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on WUF: Feces Day 8
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   4.1306 0.63601 75.0484 0.0001 ***
## pfos      1   0.0484 0.00745  0.8789 0.3884    
## van:pfos  1   0.1140 0.01756  2.0715 0.1182    
## Residual 40   2.2016 0.33899                   
## Total    43   6.4945 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.f8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8",]
perm.bray <- adonis2(bray.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Bray: Feces Day 8
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   6.1926 0.56744 57.5071 0.0001 ***
## pfos      1   0.2098 0.01923  1.9486 0.1044    
## van:pfos  1   0.2034 0.01864  1.8891 0.1119    
## Residual 40   4.3074 0.39469                   
## Total    43  10.9132 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.f8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8",]
perm.jac <- adonis2(jac.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Jaccard: Feces Day 8
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   3.9091 0.44500 34.8103 0.0001 ***
## pfos      1   0.1830 0.02084  1.6300 0.1295    
## van:pfos  1   0.2006 0.02283  1.7859 0.0977 .  
## Residual 40   4.4919 0.51134                   
## Total    43   8.7846 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
as.data.frame(perm.unif)["pfos","Pr(>F)"]
## [1] 0.0902
coef <- coefficients(perm.unif)["",]


# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4.7 PERMANOVA FECES day 8 CTRL & VAN

MTRL <- "Feces"
DAY <- "Day 8"
VAN <- "no vancomycin"

# No vancomycin treatment
message(paste0("PERMANOVA distance test for PFOS effect on ",MTRL," ",DAY," with ",VAN))
## PERMANOVA distance test for PFOS effect on Feces Day 8 with no vancomycin
# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.f8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8" & dat$van == "ctrl",]
perm.unif <- adonis2(unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on UniF: Feces Day 8 no vancomycin
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)   
## pfos      1  0.09595 0.09121 2.2081 0.0018 **
## Residual 22  0.95596 0.90879                 
## Total    23  1.05191 1.00000                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.f8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8" & dat$van == "ctrl",]
perm.wuf <- adonis2(wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on WUF: Feces Day 8 no vancomycin
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.09116 0.04693 1.0832   0.32
## Residual 22  1.85139 0.95307              
## Total    23  1.94255 1.00000
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.f8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8" & dat$van == "ctrl",]
perm.bray <- adonis2(bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Bray: Feces Day 8 no vancomycin
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1   0.2149 0.05965 1.3956 0.1604
## Residual 22   3.3868 0.94035              
## Total    23   3.6017 1.00000
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.f8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8" & dat$van == "ctrl",]
perm.jac <- adonis2(jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Jaccard: Feces Day 8 no vancomycin
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)   
## pfos      1  0.15436 0.07616 1.8136 0.0018 **
## Residual 22  1.87246 0.92384                 
## Total    23  2.02681 1.00000                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# With vancomycin treatment
VAN <- "vancomycin"
message(paste0("PERMANOVA distance test for PFOS effect on ",MTRL," ",DAY," with ",VAN))
## PERMANOVA distance test for PFOS effect on Feces Day 8 with vancomycin
# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.f8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8" & dat$van == "van",]
perm.unif <- adonis2(unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on UniF: Feces Day 8 vancomycin
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## pfos      1  0.07322 0.07483 1.4558 0.0836 .
## Residual 18  0.90531 0.92517                
## Total    19  0.97853 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.f8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8" & dat$van == "van",]
perm.wuf <- adonis2(wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on WUF: Feces Day 8 vancomycin
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## pfos      1  0.07123 0.16902 3.6613 0.0223 *
## Residual 18  0.35018 0.83098                
## Total    19  0.42140 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.f8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8" & dat$van == "van",]
perm.bray <- adonis2(bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Bray: Feces Day 8 vancomycin
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## pfos      1  0.19841 0.17732 3.8797 0.0146 *
## Residual 18  0.92052 0.82268                
## Total    19  1.11893 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.f8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Feces" & dat$day == "d8" & dat$van == "van",]
perm.jac <- adonis2(jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Jaccard: Feces Day 8 vancomycin
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)   
## pfos      1  0.22924 0.08047 1.5753 0.0059 **
## Residual 18  2.61946 0.91953                 
## Total    19  2.84870 1.00000                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4.8 PERMANOVA CECUM DAY 8

MTRL <- "Cecum"
DAY <- "Day 8"

# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.ce8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8",]
perm.unif <- adonis2(unif.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on UniF: Cecum Day 8
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   3.4798 0.61291 68.3422 0.0001 ***
## pfos      1   0.0611 0.01076  1.1995 0.2572    
## van:pfos  1   0.0491 0.00864  0.9634 0.3395    
## Residual 41   2.0876 0.36770                   
## Total    44   5.6776 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.ce8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8",]
perm.wuf <- adonis2(wuf.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on WUF: Cecum Day 8
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2        F Pr(>F)    
## van       1   5.1149 0.82681 203.6609 0.0001 ***
## pfos      1   0.0212 0.00343   0.8441 0.3675    
## van:pfos  1   0.0205 0.00332   0.8170 0.3806    
## Residual 41   1.0297 0.16645                    
## Total    44   6.1863 1.00000                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.ce8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8",]
perm.bray <- adonis2(bray.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Bray: Cecum Day 8
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   6.6972 0.57711 59.3572 0.0001 ***
## pfos      1   0.1439 0.01240  1.2750 0.2300    
## van:pfos  1   0.1377 0.01187  1.2204 0.2463    
## Residual 41   4.6260 0.39863                   
## Total    44  11.6047 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.ce8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8",]
perm.jac <- adonis2(jac.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Jaccard: Cecum Day 8
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2       F Pr(>F)    
## van       1   4.9262 0.47593 40.2910 0.0001 ***
## pfos      1   0.2106 0.02034  1.7223 0.1162    
## van:pfos  1   0.2010 0.01942  1.6442 0.1303    
## Residual 41   5.0129 0.48430                   
## Total    44  10.3507 1.00000                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
as.data.frame(perm.unif)["pfos","Pr(>F)"]
## [1] 0.2572
coef <- coefficients(perm.unif)["",]


# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4.9 PERMANOVA CECUM DAY 8 CTRL & VAN

MTRL <- "Cecum"
DAY <- "Day 8"
VAN <- "no vancomycin"

# No vancomycin treatment
message(paste0("PERMANOVA distance test for PFOS effect on ",MTRL," ",DAY," with ",VAN))
## PERMANOVA distance test for PFOS effect on Cecum Day 8 with no vancomycin
# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.ce8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8" & dat$van == "ctrl",]
perm.unif <- adonis2(unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on UniF: Cecum Day 8 no vancomycin
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.03880 0.03757 0.8197  0.783
## Residual 21  0.99395 0.96243              
## Total    22  1.03275 1.00000
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.ce8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8" & dat$van == "ctrl",]
perm.wuf <- adonis2(wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on WUF: Cecum Day 8 no vancomycin
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.01491 0.01854 0.3968 0.9175
## Residual 21  0.78924 0.98146              
## Total    22  0.80416 1.00000
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.ce8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8" & dat$van == "ctrl",]
perm.bray <- adonis2(bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Bray: Cecum Day 8 no vancomycin
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1   0.1313 0.03331 0.7237 0.7846
## Residual 21   3.8104 0.96669              
## Total    22   3.9417 1.00000
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.ce8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8" & dat$van == "ctrl",]
perm.jac <- adonis2(jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Jaccard: Cecum Day 8 no vancomycin
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.08264 0.04426 0.9726 0.5115
## Residual 21  1.78429 0.95574              
## Total    22  1.86693 1.00000
message("")
## 
# With vancomycin treatment
VAN <- "vancomycin"
message(paste0("PERMANOVA distance test for PFOS effect on ",MTRL," ",DAY," with ",VAN))
## PERMANOVA distance test for PFOS effect on Cecum Day 8 with vancomycin
# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.ce8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8" & dat$van == "van",]
perm.unif <- adonis2(unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on UniF: Cecum Day 8 vancomycin
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.07133 0.06123 1.3044 0.1607
## Residual 20  1.09367 0.93877              
## Total    21  1.16500 1.00000
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.ce8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8" & dat$van == "van",]
perm.wuf <- adonis2(wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on WUF: Cecum Day 8 vancomycin
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1 0.026805 0.10029 2.2295 0.1063
## Residual 20 0.240462 0.89971              
## Total    21 0.267268 1.00000
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.ce8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8" & dat$van == "van",]
perm.bray <- adonis2(bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Bray: Cecum Day 8 vancomycin
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)   
## pfos      1  0.15024 0.15556 3.6843 0.0098 **
## Residual 20  0.81557 0.84444                 
## Total    21  0.96581 1.00000                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.ce8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Cecum" & dat$day == "d8" & dat$van == "van",]
perm.jac <- adonis2(jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Jaccard: Cecum Day 8 vancomycin
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)    
## pfos      1   0.3290 0.09247 2.0378  1e-04 ***
## Residual 20   3.2286 0.90753                  
## Total    21   3.5576 1.00000                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4.10 PERMANOVA ILEUM DAY 8

MTRL <- "Ileum"
DAY <- "Day 8"

# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.il8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8",]
perm.unif <- adonis2(unif.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on UniF: Ileum Day 8
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)    
## van       1   0.4699 0.09427 3.3495 0.0010 ***
## pfos      1   0.1921 0.03854 1.3693 0.1341    
## van:pfos  1   0.1139 0.02285 0.8117 0.6632    
## Residual 30   4.2082 0.84434                  
## Total    33   4.9840 1.00000                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.il8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8",]
perm.wuf <- adonis2(wuf.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on WUF: Ileum Day 8
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## van       1   0.5399 0.10714 4.1609 0.0113 *
## pfos      1   0.4745 0.09415 3.6566 0.0177 *
## van:pfos  1   0.1321 0.02622 1.0181 0.3554  
## Residual 30   3.8927 0.77249                
## Total    33   5.0391 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.il8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8",]
perm.bray <- adonis2(bray.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Bray: Ileum Day 8
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)    
## van       1   1.6154 0.19070 8.2403 0.0001 ***
## pfos      1   0.6639 0.07837 3.3864 0.0110 *  
## van:pfos  1   0.3106 0.03666 1.5842 0.1613    
## Residual 30   5.8810 0.69427                  
## Total    33   8.4707 1.00000                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.il8"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8",]
perm.jac <- adonis2(jac.sub.dist ~ van*pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY))
## PERMANOVA on Jaccard: Ileum Day 8
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ van * pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)    
## van       1   0.8268 0.10826 3.9198 0.0001 ***
## pfos      1   0.2992 0.03918 1.4186 0.0746 .  
## van:pfos  1   0.1831 0.02397 0.8679 0.6287    
## Residual 30   6.3282 0.82858                  
## Total    33   7.6373 1.00000                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
as.data.frame(perm.unif)["pfos","Pr(>F)"]
## [1] 0.1341
coef <- coefficients(perm.unif)["",]


# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

4.11 PERMANOVA ILEUM DAY 8 CTRL & VAN

MTRL <- "Ileum"
DAY <- "Day 8"
VAN <- "no vancomycin"

# No vancomycin treatment
message(paste0("PERMANOVA distance test for PFOS effect on ",MTRL," ",DAY," with ",VAN))
## PERMANOVA distance test for PFOS effect on Ileum Day 8 with no vancomycin
# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.il8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8" & dat$van == "ctrl",]
perm.unif <- adonis2(unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on UniF: Ileum Day 8 no vancomycin
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs     R2      F Pr(>F)
## pfos      1  0.10365 0.0543 0.7464 0.6979
## Residual 13  1.80513 0.9457              
## Total    14  1.90878 1.0000
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.il8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8" & dat$van == "ctrl",]
perm.wuf <- adonis2(wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on WUF: Ileum Day 8 no vancomycin
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1   0.2623 0.12134 1.7953 0.1205
## Residual 13   1.8993 0.87866              
## Total    14   2.1616 1.00000
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.il8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8" & dat$van == "ctrl",]
perm.bray <- adonis2(bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Bray: Ileum Day 8 no vancomycin
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## pfos      1   0.5266 0.14394 2.1859 0.0661 .
## Residual 13   3.1319 0.85606                
## Total    14   3.6586 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.il8_ctrl"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8" & dat$van == "ctrl",]
perm.jac <- adonis2(jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Jaccard: Ileum Day 8 no vancomycin
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1  0.18353 0.06956 0.9719 0.4359
## Residual 13  2.45491 0.93044              
## Total    14  2.63844 1.00000
message("")
## 
# With vancomycin treatment
VAN <- "vancomycin"
message(paste0("PERMANOVA distance test for PFOS effect on ",MTRL," ",DAY," with ",VAN))
## PERMANOVA distance test for PFOS effect on Ileum Day 8 with vancomycin
# UniF
METRIC <- "UniF"
SUBNAME <- "unif.sub.il8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8" & dat$van == "van",]
perm.unif <- adonis2(unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on UniF: Ileum Day 8 vancomycin
perm.unif
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = unif.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)
## pfos      1   0.2023 0.07765 1.4311 0.1143
## Residual 17   2.4031 0.92235              
## Total    18   2.6054 1.00000
message("")
## 
# WUF
METRIC <- "WUF"
SUBNAME <- "wuf.sub.il8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8" & dat$van == "van",]
perm.wuf <- adonis2(wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on WUF: Ileum Day 8 vancomycin
perm.wuf
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = wuf.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## pfos      1  0.34427 0.14727 2.9361 0.0687 .
## Residual 17  1.99333 0.85273                
## Total    18  2.33760 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# BRAY
METRIC <- "Bray"
SUBNAME <- "bray.sub.il8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8" & dat$van == "van",]
perm.bray <- adonis2(bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Bray: Ileum Day 8 vancomycin
perm.bray
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = bray.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## pfos      1   0.4478 0.14007 2.7691 0.0562 .
## Residual 17   2.7490 0.85993                
## Total    18   3.1968 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
message("")
## 
# Jaccard
METRIC <- "Jaccard"
SUBNAME <- "jac.sub.il8_van"
load(paste0("R_objects/",SUBNAME,".RData"))
load(params$input)

dat <- data.frame(sample_data(phy))
dat <- dat[dat$material == "Ileum" & dat$day == "d8" & dat$van == "van",]
perm.jac <- adonis2(jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
message(paste0("PERMANOVA on ",METRIC,": ",MTRL," ",DAY," ",VAN))
## PERMANOVA on Jaccard: Ileum Day 8 vancomycin
perm.jac
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = jac.sub.dist ~ pfos, data = dat, permutations = 9999, na.action = na.omit)
##          Df SumOfSqs      R2      F Pr(>F)  
## pfos      1   0.2988 0.07162 1.3115 0.0919 .
## Residual 17   3.8733 0.92838                
## Total    18   4.1721 1.00000                
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

5 ANALYSES NOT INCLUDED IN PUBLICATION

Following code chunks have been used in the processing of data but are not used for content of the paper.

5.1 DISTANCE COMPARISON BOXPLOTS

Section under development for creating a statistic and visual for distance differences between treatment groups or days for each iteration created above. First section is a manual setup followed by a section with a for-loop generating plots for each iteration listed. THIS SECTION SHOULD MOST LIKELY BE DELETED FROM FINAL SCRIPT.

params <- readRDS("R_objects/bdiv_params.RDS")
load("R_objects/Phyloseq_rarefied.RData")
# load(params$input)
METRIC <- "Bray"
SUBNAME <- "f8_van"
MTRL <- "Feces"
DAY <- "d8"
VAN <- "van"

COL <- c("#606060","#31b44b")

# SUBSET
phy.sub <- subset_samples(phy.rare, material == MTRL & day %in% DAY & van == VAN)

# Transform original data
phy.rl <- transform_sample_counts(phy.sub, function(x) x/sum(x))
phy.rl
head(otu_table(phy.rl)[,1:6])
bray.dist <- distance(phy.rl, method = "bray",)

# Create matrix from distances
bray.m <- melt(as.matrix(bray.dist))
bray.m

# Remove self-comparisons
bray.m <- bray.m %>%
  filter(as.character(Var1) != as.character(Var2)) %>%
  mutate_if(is.factor,as.character)
bray.m

# Get sample data
sd <- data.frame(sample_data(phy.rl))
sd <- sd %>%
select(ID, treatment) %>%
mutate_if(is.factor,as.character)
sd

# Combine distances with sample data
colnames(sd) <- c("Var1","Treat1")
bray.sd <- left_join(bray.m, sd, by = "Var1")

colnames(sd) <- c("Var2","Treat2")
bray.sd <- left_join(bray.sd,sd,by = "Var2")

#bray.sd$group <- paste(bray.sd$Treat1, bray.sd$Treat2, sep = "_")
bray.sd

write.csv(file = paste0("output/bdiv_comparison_boxplot_",MTRL,"_",DAY,"_",VAN,"_",METRIC,"_.csv"),bray.sd)

# Create boxplot
p <- ggplot(bray.sd, aes(x = Treat2, y = value)) +
  theme_bw() +
  geom_boxplot(aes(color = ifelse(Treat1 == Treat2, "red", "black"))) +
  geom_point(position = position_jitter(height = 0.2,width = 0.2)) +
  scale_color_identity() +
  facet_wrap(~ Treat1, scales = "free_x") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
  ggtitle(paste0("Distance metric = ",METRIC)) +
  labs(x ="Treatment",y="Distance")
p
#p.stat <- p + stat_pvalue_manual(stat.sig, label = "p.adj.format",tip.length = 0)

suppressMessages(ggsave(filename = paste0("plots/bdiv/beta_",SUBNAME,"/",METRIC,"_boxplot_",SUBNAME,".png"), p, device = "png", units = "mm", width = 350, height = 200, dpi = 300))
# clear the environment and release memory
rm(list = ls(all.names = TRUE)[ls(all.names = TRUE) != "params"])
invisible(gc())

5.2 DISTANCE COMPARISON ALL

params <- readRDS("R_objects/bdiv_params.RDS")

str.subnameT<- c("feces_ctrl","feces_pfos","feces_van","feces_vanpfos",
                 "f0","f0_ctrl","f0_van","f2","f2_ctrl","f2_van",
                 "f4","f4_ctrl","f4_van",
                 "f8","f8_ctrl","f8_van",
                 "il8","il8_ctrl","il8_van",
                 "ce8","ce8_ctrl","ce8_van",
                 "f08","f0248","fceil8")

for (SUBNAME in str.subnameT) {
  for (METRIC in params$metrices) {
  # Load data
    load(params$input)
    #METRIC <- "UniF"
    if (METRIC == "UniF") {
      filename <- paste0("R_objects/unif.sub.",SUBNAME,".RData")
      load(filename)
      dist.used <- unif.sub.dist
      nmds.used <- unif.sub.nmds
      pcoa.used <- unif.sub.pcoa
      rm(unif.sub.dist, unif.sub.nmds, unif.sub.pcoa)
    } else if (METRIC == "WUF") {
      filename <- paste0("R_objects/wuf.sub.",SUBNAME,".RData")
      load(filename)
      dist.used <- wuf.sub.dist
      nmds.used <- wuf.sub.nmds
      pcoa.used <- wuf.sub.pcoa
      rm(wuf.sub.dist, wuf.sub.nmds, wuf.sub.pcoa)
    } else if (METRIC == "Bray"){
      filename <- paste0("R_objects/bray.sub.",SUBNAME,".RData")
      load(filename)
      dist.used <- bray.sub.dist
      nmds.used <- bray.sub.nmds
      pcoa.used <- bray.sub.pcoa
      rm(bray.sub.dist, bray.sub.nmds, bray.sub.pcoa)
    } else if (METRIC == "Jaccard"){
      filename <- paste0("R_objects/jac.sub.",SUBNAME,".RData")
      load(filename)
      dist.used <- jac.sub.dist
      nmds.used <- jac.sub.nmds
      pcoa.used <- jac.sub.pcoa
      rm(jac.sub.dist, jac.sub.nmds, jac.sub.pcoa)
    }
load("R_objects/Bray.RData")
load(params$input)
METRIC <- "Bray"
# Transform original data
phy.ra <- transform_sample_counts(phy, function(x) x/sum(x))
phy.ra
head(otu_table(phy.ra)[,1:6])
bray.dist <- distance(phy.ra, method = "bray",)
# Create matrix from distances
bray.mtx <- melt(as.matrix(bray.dist))
bray.mtx

# Remove self-comparisons
bray.mtx <- bray.mtx %>%
  filter(as.character(Var1) != as.character(Var2)) %>%
  mutate_if(is.factor,as.character)
bray.mtx

# Get sample data
sd <- data.frame(sample_data(phy))
sd <- sd %>%
select (ID, treatment) %>%
mutate_if(is.factor,as.character)

# Combine distances with sample data
colnames(sd) <- c("Var1","Type1")
bray.sd <- left_join(bray.mtx, sd, by = "Var1")

colnames(sd) <- c("Var2","Type2")
bray.sd <- left_join(bray.sd,sd,by = "Var2")

write.csv(file = "output/bdiv_comparison_boxplot.csv",bray.sd)

# Create boxplot
bdiv.comp <- ggplot(bray.sd, aes(x = Type2, y = value)) +
  theme_bw() +
  geom_point() +
  geom_boxplot(aes(color = ifelse(Type1 == Type2, "red", "black"))) +
  scale_color_identity() +
  facet_wrap(~ Type1, scales = "free_x") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
  ggtitle(paste0("Distance metric = ",METRIC))

suppressMessages(ggsave(filename = paste0("plots/bdiv/",SUBNAME,"/",METRIC,"_boxplot_",SUBNAME,".png"), bdiv.comp, device = "png", units = "mm", width = 350, height = 200, dpi = 300))
}

6 SETTINGS

Overview of the parameters and packages that were used for this analysis

6.1 PARAMETERS

The following paramenters were set in for this analysis:

params <- readRDS("R_objects/bdiv_params.RDS")

tmp <- unlist(params)
dat <- data.frame(Parameter = names(tmp), Value = unname(tmp))


kbl(dat, row.names = F) %>% kable_classic(lightable_options = "striped")
Parameter Value
input R_objects/Phyloseq_15000.Rdata
batch run
metrices1 UniF
metrices2 Bray

6.2 PACKAGES

The analysis was run in R version 4.2.3 using the following packages:

pack <- data.frame(Package = (.packages()))

for (i in seq(nrow(pack))) pack$Version[i] <- as.character(packageVersion(pack$Package[i]))

kbl(pack[order(pack$Package),], row.names = F) %>% kable_classic(lightable_options = "striped")   
Package Version
ape 5.7.1
base 4.2.3
cowplot 1.1.1
datasets 4.2.3
dplyr 1.1.0
forcats 1.0.0
ggExtra 0.10.0.9000
ggplot2 3.4.1
ggpubr 0.6.0
graphics 4.2.3
grDevices 4.2.3
kableExtra 1.3.4
lattice 0.20.45
lubridate 1.9.2
methods 4.2.3
permute 0.9.7
phyloseq 1.42.0
purrr 1.0.1
readr 2.1.4
reshape2 1.4.4
rstatix 0.7.2
stats 4.2.3
stringr 1.5.0
tibble 3.2.1
tidyr 1.3.0
tidyverse 2.0.0
utils 4.2.3
vegan 2.6.4